Skip to content

Change type requirements for {} being a set literal. #129

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Dec 18, 2018
Merged

Conversation

lrhn
Copy link
Member

@lrhn lrhn commented Dec 11, 2018

Use LinkedHashSet<Null> as the comparison, not Set<Null>. This ensures that:

LinkedHashSet<int> s = {};

is valid. Since we guarantee to return a LinkedHashSet, that is perfectly fine code.

lrhn added 2 commits December 10, 2018 17:04
The existing rule had some issue. My immediate fix would have different issues. The `FutureOr` case is particularly annoying because `FutureOr<LinkedHashSet<X>>` as a context type should create a `Set<X>`, and `FutureOr<V>` is a super-type of `V` and we don't want to get into zig-zag problems (`Iterable<int>`  is incomarable to `List<num>`, and `Iterable<int>` is incomparable to `FutureOr<List<int>>`).

This change requires answering a negative universal property, but I believe the types in question must be available in the context type, so it should be simple (get the `T` type as the type parameter of `Iterable` if the context type implements iterable, get the `K` and `V` as the type parmeters of `Map` if the context type implements `Map`, and you only need to check those).
@mit-mit
Copy link
Member

mit-mit commented Dec 17, 2018

@lrhn can we land this?

Copy link
Member

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LinkedHashSet and LinkedHashMap are both defined in dart:collection. So far the analyzer has only needed to know about dart:core and dart:async in order to analyze code. I don't know how big the impact on the analyzer would be of requiring it to be able to also access code from dart:collection, but it won't be free and it will likely postpone our ability to implement this feature until sometime in Q1.

@stereotype441

@stereotype441
Copy link
Member

LinkedHashSet and LinkedHashMap are both defined in dart:collection. So far the analyzer has only needed to know about dart:core and dart:async in order to analyze code. I don't know how big the impact on the analyzer would be of requiring it to be able to also access code from dart:collection, but it won't be free and it will likely postpone our ability to implement this feature until sometime in Q1.

Hmm, I agree that we probably can't modify the analyzer to adapt to this change before January--most members of the analyzer team will be leaving for the holidays later this week and there's too much other work on our plate.

However, regarding the analyzer's need to know about dart:collection, that's actually unchanged by this proposal; even if we don't make this change, the spec already says that the analyzer should consider the "exact type" of a non-const set literal to be LinkedHashSet<T>. It looks like the current analyzer implementation gets that wrong, and I've filed dart-lang/sdk#35431 to track the bug. It's a rare enough corner case that I don't think we necessarily need to fix it before enabling the "set literals" feature.

The change described in this PR also only affects a rare corner case. So if the language team decides to land this PR, I think it would be fine to treat it the same way; as a bug in the analyzer that we don't necessarily need to fix before enabling the "set literals" feature.

Copy link
Member

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that the impact on analyzer is acceptable, the wording lgtm.

@stereotype441
Copy link
Member

Note: I filed dart-lang/sdk#35439 as a reminder to change the analyzer implementation.

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

Successfully merging this pull request may close these issues.

5 participants