Skip to content

Compile-time error errors due to exact types of set literals #230

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

Closed
kmillikin opened this issue Jan 24, 2019 · 4 comments
Closed

Compile-time error errors due to exact types of set literals #230

kmillikin opened this issue Jan 24, 2019 · 4 comments
Assignees

Comments

@kmillikin
Copy link

kmillikin commented Jan 24, 2019

LanguageFeatures/Set-literals/exact_types_of_literals_A01_t03.dart has:

  LinkedHashSet<int> v11 = {};
  Expect.isTrue(v11 is LinkedHashSet<int>);

The first line is a compile-time error. The empty non-const set/map literal is a set literal, so it has static type Set<T> for some T.

Type inference tries to satisfy Set<T> <: LinkedHashSet<int> by choosing T but there is no such T and so it infers Set<dynamic>.

The rules for exact types of literals require us to reject the assignment of the Set<dynamic> to LinkedHashSet<int> with a compile-time error because LinkedHashSet<int> is not a supertype of LinkedHashSet<dynamic>.

@kmillikin kmillikin changed the title Compile-time error in LanguageFeatures/Set-literals/exact_types_of_literals_A01_t03.dart Compile-time error errors due to exact types of set literals Jan 24, 2019
@kmillikin
Copy link
Author

For the same reason, LanguageFeatures/Set-literals/semantics_A05_t01.dart has a compile-time error. It has:

LinkedHashSet<int> test4() => {};

which is a compile-time error.

@lrhn
Copy link
Member

lrhn commented Jan 25, 2019

Correct. The "exact type" for set and map literals is going to be Set<T>/Map<K,V>, and not any of the LinkedHash-subclasses.
I originally said something else in the feature document, but that was based on a misunderstanding of what we currently do for maps. This has (now) been fixed to match the formal language specification (which is now complete and should be used as the source of truth for this feature).

@sgrekhov
Copy link
Contributor

sgrekhov commented Feb 11, 2019

@lrhn, please, update feature specification examples section. It contains

/*
context expression runtime type and const-ness
*/
...
LinkedHashSet< int > v11 = {}; // LinkedHashSet< int >

I can add an issue for Language, if needed

@sgrekhov sgrekhov self-assigned this Feb 11, 2019
@lrhn
Copy link
Member

lrhn commented Feb 11, 2019

Good catch. I've fixed it

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

3 participants