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

make lookup operator honor refined return type of "get()" #1411

Open
jvasileff opened this issue Aug 29, 2015 · 1 comment
Open

make lookup operator honor refined return type of "get()" #1411

jvasileff opened this issue Aug 29, 2015 · 1 comment

Comments

@jvasileff
Copy link
Member

In "6.8.7. Correspondence, subrange, and stream operators", the lookup operator is defined as yielding the result of lhs.get(index) with type Y? for lhs Correspondence<X,Y>. But the actual return type of lhs.get(index) may be a subtype of Y?.

It would be nice if the lookup operator honored the actual return type of get rather than assuming an optional type.

Usage example:

object multimap satisfies Correspondence<String, [Integer*]> {
    shared actual Boolean defines(String key) => nothing;
    shared actual [Integer*] get(String key) => [];
}
[Integer*] result1 = multimap[""]; // error Integer[]? is not assignable to Integer[]
[Integer*] result2 = multimap.get(""); // ok
@gdejohn
Copy link

gdejohn commented Aug 29, 2015

👍

I've had this same thought.

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