Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array literal with explicit as type uses alias of given type. #2122

Closed
jemc opened this issue Aug 2, 2017 · 1 comment
Closed

Array literal with explicit as type uses alias of given type. #2122

jemc opened this issue Aug 2, 2017 · 1 comment
Assignees

Comments

@jemc
Copy link
Member

jemc commented Aug 2, 2017

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:

trait iso T
class iso A is T
class iso B is T
class iso C is T

actor Main
  new create(env: Env) =>
    let a: T = A
    let b: T = B
    let c: T = C
    let abc: Array[T] = [as T^: A; B; C] // works
    let abc': Array[T] = [as T: 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?

@jemc
Copy link
Member Author

jemc commented Aug 2, 2017

We decided on the sync call that this was a principle of least surprise bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants