fix(compiler): Fix CRDT Map in array handling [LNG-370] (#1171)

* Stricten CollectibleType

* Add test

* Add comment
This commit is contained in:
InversionSpaces 2024-07-12 11:06:14 +02:00 committed by GitHub
parent af3fc24adb
commit b0f3a8c21e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 4 deletions

View File

@ -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("*")
}
}

View File

@ -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
}
@ -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 {