You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across this behaviour while working on #2094.
It appears that an array literal, even when the as type is given explicitly, uses the alias of the as type as the type argument for the Array type. Consider the following example:
traitisoTclassisoA is TclassisoB is TclassisoC is TactorMainnewcreate(env: Env) =>
let a: T = Alet b: T = Blet c: T = Clet abc: Array[T] = [asT^: A; B; C] // workslet abc': Array[T] = [asT: A; B; C] // fails: literal has type Array[T!]
I can understand why this works the way it does (the literal elements must actually have type T^ so that they can be pushed into an Array[T]), but I think it's cumbersome, and also surprising that it doesn't follow the same semantics as a let reference with a type (compare the first few lines of the example above with the array literal lines).
I'm going to propose this be shifted so that the semantics of the element type as it relates to the type argument is still the same (the alias of the element type is the type argument), but the as type is considered to be the aliased element type, not the pre-aliasing element type. In other words, the as type would just be the type argument that gets passed to the Array.
I think this would be less cumbersome and less confusing. Thoughts?
The text was updated successfully, but these errors were encountered:
I came across this behaviour while working on #2094.
It appears that an array literal, even when the
as
type is given explicitly, uses the alias of theas
type as the type argument for theArray
type. Consider the following example:I can understand why this works the way it does (the literal elements must actually have type
T^
so that they can bepush
ed into anArray[T]
), but I think it's cumbersome, and also surprising that it doesn't follow the same semantics as alet
reference with a type (compare the first few lines of the example above with the array literal lines).I'm going to propose this be shifted so that the semantics of the element type as it relates to the type argument is still the same (the alias of the element type is the type argument), but the
as
type is considered to be the aliased element type, not the pre-aliasing element type. In other words, theas
type would just be the type argument that gets passed to theArray
.I think this would be less cumbersome and less confusing. Thoughts?
The text was updated successfully, but these errors were encountered: