Skip to content

Commit

Permalink
fix(compiler): Fix CRDT Map in array handling [LNG-370] (#1171)
Browse files Browse the repository at this point in the history
* Stricten CollectibleType

* Add test

* Add comment
  • Loading branch information
InversionSpaces authored Jul 12, 2024
1 parent af3fc24 commit b0f3a8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
21 changes: 21 additions & 0 deletions semantics/src/test/scala/aqua/semantics/SemanticsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1012,4 +1012,25 @@ class SemanticsSpec extends AnyFlatSpec with Matchers with Inside {
atLeast(1, errors.toChain.toList) shouldBe a[RulesViolated[Span.S]]
}
}

// NOTE: This should be true until aqua has immutable map type
it should "prohibit putting stream maps into collection" in {
def test(prefix: String = "") = {
val script = s"""|func test(arr: []⊤) -> string:
| <- "test"
|
|func main() -> string:
| map: %string
| <- test(${prefix}[map])""".stripMargin

insideSemErrors(script) { errors =>
errors.collect { case RulesViolated(_, messages) => messages }.toList.flatten
.contains("Value of type '%string' could not be put into a collection") shouldBe (true)
}
}

test()
test("?")
test("*")
}
}
11 changes: 7 additions & 4 deletions types/src/main/scala/aqua/types/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ object CollectionType {
sealed trait ImmutableCollectionType extends CollectionType with DataType {
def withElement(t: DataType): ImmutableCollectionType
}

sealed trait MutableStreamType extends CollectionType {
def toCanon: ImmutableCollectionType
}
Expand Down Expand Up @@ -389,7 +390,7 @@ case class StreamMapType(override val element: DataType) extends MutableStreamTy

override def toString: String = s"%$element"

def getFunc(f: Func): ArrowType ={
def getFunc(f: Func): ArrowType = {
val (args, rets) = f match {
case Get =>
(ScalarType.string :: Nil) -> (ArrayType(element) :: Nil)
Expand Down Expand Up @@ -431,7 +432,7 @@ object StreamMapType {
def funcByString(s: String): Option[Func] =
Func.values.find(_.name == s)

lazy val allFuncs: List[Func] = Func.values.toList
lazy val allFuncs: List[Func] = Func.values.toList

def top(): StreamMapType = StreamMapType(TopType)
}
Expand Down Expand Up @@ -602,9 +603,11 @@ case class ArrowType(domain: ProductType, codomain: ProductType) extends Type {
object Type {

/**
* `StreamType` is collectible with canonicalization
* `StreamType` is collectible with canonicalization.
* Note: until aqua type system has immutable maps,
* they are not collectible
*/
type CollectibleType = DataType | MutableStreamType
type CollectibleType = DataType | StreamType

def isStreamType(t: Type): Boolean =
t match {
Expand Down

0 comments on commit b0f3a8c

Please sign in to comment.