diff --git a/aqua-src/antithesis.aqua b/aqua-src/antithesis.aqua index ddd2312b..b9042770 100644 --- a/aqua-src/antithesis.aqua +++ b/aqua-src/antithesis.aqua @@ -1,3 +1,3 @@ func z() -> string: - arr = nil + arr = [] <- arr! \ No newline at end of file diff --git a/semantics/src/test/scala/aqua/semantics/ArrowSemSpec.scala b/semantics/src/test/scala/aqua/semantics/ArrowSemSpec.scala index 1620dd1e..1389b0e1 100644 --- a/semantics/src/test/scala/aqua/semantics/ArrowSemSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/ArrowSemSpec.scala @@ -1,7 +1,7 @@ package aqua.semantics import aqua.parser.expr.func.ArrowExpr -import aqua.parser.lexer.{BasicTypeToken, Name} +import aqua.parser.lexer.BasicTypeToken import aqua.raw.Raw import aqua.raw.arrow.ArrowRaw import aqua.raw.ops.* @@ -12,20 +12,17 @@ import aqua.types.* import aqua.types.ScalarType.* import cats.Id -import cats.syntax.applicative.* import cats.data.{NonEmptyList, NonEmptyMap, State} -import org.scalatest.EitherValues +import cats.syntax.applicative.* +import org.scalatest.{EitherValues, Inside} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import org.scalatest.Inside class ArrowSemSpec extends AnyFlatSpec with Matchers with EitherValues with Inside { - import Utils.{given, *} + import Utils.{*, given} def program(arrowStr: String): Prog[State[CompilerState[cats.Id], *], Raw] = { - import CompilerState.* - val expr = ArrowExpr.p.parseAll(arrowStr).value.mapK(spanToId) val sem = new ArrowSem[Id](expr) diff --git a/semantics/src/test/scala/aqua/semantics/AssignmentSemSpec.scala b/semantics/src/test/scala/aqua/semantics/AssignmentSemSpec.scala new file mode 100644 index 00000000..8caafd9a --- /dev/null +++ b/semantics/src/test/scala/aqua/semantics/AssignmentSemSpec.scala @@ -0,0 +1,48 @@ +package aqua.semantics + +import aqua.parser.expr.func.{AssignmentExpr, ClosureExpr} +import aqua.parser.lexer.CollectionToken.Mode.ArrayMode +import aqua.parser.lexer.{CollectionToken, Name, VarToken} +import aqua.parser.lift.Span +import aqua.raw.Raw +import aqua.semantics.expr.func.{AssignmentSem, ClosureSem} + +import cats.Id +import cats.data.State +import org.scalatest.Inside +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class AssignmentSemSpec extends AnyFlatSpec with Matchers with Inside { + + import Utils.{*, given} + + val program: Prog[State[CompilerState[cats.Id], *], Raw] = { + val expr = ClosureExpr(Name[Id]("closure"), None) + val sem = new ClosureSem[Id](expr) + + sem.program[State[CompilerState[Id], *]] + } + + "it" should "throw an error on 'nil'" in { + val expr = AssignmentExpr(Name[Id]("emptyArr"), VarToken[Id](Name[Id]("nil"))) + val sem = new AssignmentSem[Id](expr) + + val state = getState(sem.program[State[CompilerState[Id], *]]) + + inside(state.errors) { errors => + atLeast(1, errors.toList) shouldBe a[RulesViolated[Span.S]] + } + } + + "it" should "throw an error on empty array" in { + val expr = AssignmentExpr(Name[Id]("emptyArr"), CollectionToken[Id](ArrayMode, Nil)) + val sem = new AssignmentSem[Id](expr) + + val state = getState(sem.program[State[CompilerState[Id], *]]) + + inside(state.errors) { errors => + atLeast(1, errors.toList) shouldBe a[RulesViolated[Span.S]] + } + } +} diff --git a/semantics/src/test/scala/aqua/semantics/ClosureSemSpec.scala b/semantics/src/test/scala/aqua/semantics/ClosureSemSpec.scala index 252b6b59..e42b84dc 100644 --- a/semantics/src/test/scala/aqua/semantics/ClosureSemSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/ClosureSemSpec.scala @@ -1,38 +1,24 @@ package aqua.semantics import aqua.parser.expr.func.ClosureExpr -import aqua.parser.lexer.{Name, Token} -import aqua.raw.arrow.ArrowRaw +import aqua.parser.lexer.Name import aqua.raw.Raw -import aqua.raw.ops.{EmptyTag, FuncOp, RawTag} +import aqua.raw.arrow.ArrowRaw +import aqua.raw.ops.RawTag import aqua.semantics.expr.func.ClosureSem -import aqua.semantics.rules.names.{NamesInterpreter, NamesState} import aqua.types.{ArrowType, ProductType} + +import cats.Id import cats.data.* import cats.data.State.* -import cats.instances.all.* -import cats.syntax.all.* -import cats.syntax.applicative.* -import cats.syntax.apply.* -import cats.syntax.bifunctor.* -import cats.syntax.comonad.* -import cats.syntax.flatMap.* -import cats.syntax.functor.* -import cats.syntax.monad.* -import cats.syntax.semigroup.* -import cats.{catsInstancesForId, Id, Monad} -import monocle.Lens -import monocle.macros.GenLens -import monocle.syntax.all.* import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers class ClosureSemSpec extends AnyFlatSpec with Matchers { - import Utils.{given, *} + import Utils.{*, given} val program: Prog[State[CompilerState[cats.Id], *], Raw] = { - import CompilerState.* val expr = ClosureExpr(Name[Id]("closure"), None) val sem = new ClosureSem[Id](expr) diff --git a/semantics/src/test/scala/aqua/semantics/HeaderSpec.scala b/semantics/src/test/scala/aqua/semantics/HeaderSpec.scala index fa89dc54..c527b2f8 100644 --- a/semantics/src/test/scala/aqua/semantics/HeaderSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/HeaderSpec.scala @@ -5,14 +5,13 @@ import aqua.parser.lexer.{Ability, Name} import aqua.raw.RawContext import aqua.raw.arrow.{ArrowRaw, FuncRaw} import aqua.raw.ops.RawTag -import aqua.raw.value.VarRaw import aqua.semantics.header.{HeaderHandler, HeaderSem} -import aqua.types.{AbilityType, ArrowType, NilType, ProductType, ScalarType} +import aqua.types.* import cats.data.{Chain, NonEmptyList, NonEmptyMap, Validated} import cats.free.Cofree -import cats.{Eval, Id, Monoid} import cats.syntax.applicative.* +import cats.{Eval, Id, Monoid} import org.scalatest.Inside import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers diff --git a/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala b/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala index 04147a4b..35228644 100644 --- a/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala @@ -1,26 +1,19 @@ package aqua.semantics -import aqua.raw.RawContext -import aqua.parser.Ast -import aqua.raw.ops.{Call, CallArrowRawTag, FuncOp, OnTag, ParTag, RawTag, SeqGroupTag, SeqTag} -import aqua.parser.Parser +import aqua.parser.{Ast, Parser} import aqua.parser.lift.{LiftParser, Span} +import aqua.raw.RawContext +import aqua.raw.ops.* import aqua.raw.value.* import aqua.types.* -import aqua.raw.ops.* +import cats.Eval +import cats.data.{Chain, EitherNec, NonEmptyChain, Validated} +import cats.free.Cofree +import cats.syntax.foldable.* +import org.scalatest.Inside import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import org.scalatest.Inside -import cats.~> -import cats.data.{Chain, EitherNec, NonEmptyChain} -import cats.syntax.show.* -import cats.syntax.traverse.* -import cats.syntax.foldable.* -import cats.data.Validated -import cats.free.Cofree -import cats.data.State -import cats.Eval class SemanticsSpec extends AnyFlatSpec with Matchers with Inside { diff --git a/semantics/src/test/scala/aqua/semantics/Utils.scala b/semantics/src/test/scala/aqua/semantics/Utils.scala index b00280be..aef64fa9 100644 --- a/semantics/src/test/scala/aqua/semantics/Utils.scala +++ b/semantics/src/test/scala/aqua/semantics/Utils.scala @@ -1,23 +1,17 @@ package aqua.semantics -import aqua.parser.expr.func.ClosureExpr -import aqua.parser.lexer.{Name, Token} import aqua.parser.lift.Span import aqua.raw.{Raw, RawContext} -import aqua.semantics.expr.func.ClosureSem -import aqua.semantics.rules.abilities.{AbilitiesAlgebra, AbilitiesInterpreter, AbilitiesState} +import aqua.semantics.rules.abilities.{AbilitiesAlgebra, AbilitiesInterpreter} import aqua.semantics.rules.locations.{DummyLocationsInterpreter, LocationsAlgebra} -import aqua.semantics.rules.names.{NamesAlgebra, NamesInterpreter, NamesState} -import aqua.semantics.rules.types.{TypesAlgebra, TypesInterpreter, TypesState} import aqua.semantics.rules.mangler.{ManglerAlgebra, ManglerInterpreter} +import aqua.semantics.rules.names.{NamesAlgebra, NamesInterpreter} import aqua.semantics.rules.report.{ReportAlgebra, ReportInterpreter} +import aqua.semantics.rules.types.{TypesAlgebra, TypesInterpreter} import aqua.types.* import cats.data.State -import cats.{~>, Id} -import monocle.Lens -import monocle.macros.GenLens -import monocle.syntax.all.* +import cats.{Id, ~>} object Utils { @@ -50,6 +44,10 @@ object Utils { prog.apply(emptyS).run(blankCS).value._2 } + def getState(prog: Prog[State[CompilerState[cats.Id], *], Raw]): CompilerState[Id] = { + prog.apply(emptyS).run(blankCS).value._1 + } + def getState( startState: Raw )(prog: Prog[State[CompilerState[cats.Id], *], Raw]): CompilerState[Id] = { diff --git a/semantics/src/test/scala/aqua/semantics/ValuesAlgebraSpec.scala b/semantics/src/test/scala/aqua/semantics/ValuesAlgebraSpec.scala index 41309126..e041a5fe 100644 --- a/semantics/src/test/scala/aqua/semantics/ValuesAlgebraSpec.scala +++ b/semantics/src/test/scala/aqua/semantics/ValuesAlgebraSpec.scala @@ -12,6 +12,7 @@ import aqua.semantics.rules.names.{NamesAlgebra, NamesInterpreter, NamesState} import aqua.semantics.rules.report.{ReportAlgebra, ReportInterpreter} import aqua.semantics.rules.types.{TypesAlgebra, TypesInterpreter} import aqua.types.* + import cats.Id import cats.data.{NonEmptyList, NonEmptyMap, State} import monocle.syntax.all.*