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

Analyzer function type parameters are not correctly scoped #30379

Closed
leafpetersen opened this issue Aug 9, 2017 · 5 comments
Closed

Analyzer function type parameters are not correctly scoped #30379

leafpetersen opened this issue Aug 9, 2017 · 5 comments
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@leafpetersen
Copy link
Member

In the following, G and H are entirely equivalent, and neither of them are subtype related to F<T> for non-trivial T, but F<T> and G (but not H) are considered assignable.

typedef F<T> = int Function<S>(T x);
typedef G = int Function<T>(T x);
typedef H = int Function<Q>(Q x);

void test(bool b) {
   int Function<T>(F<T> f) f1;
   int Function<T>(G f) f2;
   int Function<T>(H f) f3;
   f1 = f2; // Should be error, IS NOT
   f1 = f3; // Should be error, is
   f2 = f1; // Should be error, IS NOT
   f2 = f3; // Should be ok, is
   f3 = f1; // Should be error, is
   f3 = f2; // Should be ok, is
}
@leafpetersen leafpetersen added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 9, 2017
@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Aug 9, 2017
@jmesserly
Copy link

this might be related: #30375

@jmesserly
Copy link

jmesserly commented Aug 9, 2017

working through the types:

f1 is <T> (<S> T -> int ) -> int
f2 is <T> (<T'> T' -> int ) -> int
f3 is <T> (<Q> Q -> int ) -> int

The fact that f2 has the problems is scary... f2 and f3 should be identical.

We did have a capture bug here: #29778 (comment) ... any time we create a synthetic function type we hit major problems with substitutions. That could be related.

Another problem that scared me recently when reading the code, is whether our "fresh" type variables are actually treated as non-equal to existing type variables or to other "fresh" type variables that have the same name. I worried that synthetic type variables might be falling back to name-based equality. (analyzer uses name-based equality for elements, where the name is "fully-qualified". but I don't know if this can distinguish type variables declared in the same scope, like each T for f1/f2/f3, or if it takes into account synthetic type variables that don't have any parent chain.)

@jmesserly
Copy link

@leafpetersen I can help look into this if you have not started already

@jmesserly jmesserly self-assigned this Aug 9, 2017
@leafpetersen
Copy link
Member Author

All yours if you want it, though not sure it's top priority. Just getting a test written to be sure that the new front end does the right thing might be a good start.

@srawlins
Copy link
Member

This is now fixed. In the example, there are errors reported on lines 9, 10, 11, and 13:

Analyzing 30379.dart...
  error • A value of type 'int Function<T₀>(int Function<T>(T))' can't be assigned to a variable of type 'int Function<T>(int Function<S>(T))'. • 30379.dart:9:9 • invalid_assignment
  error • A value of type 'int Function<T>(int Function<Q>(Q))' can't be assigned to a variable of type 'int Function<T>(int Function<S>(T))'. • 30379.dart:10:9 • invalid_assignment
  error • A value of type 'int Function<T>(int Function<S>(T))' can't be assigned to a variable of type 'int Function<T₀>(int Function<T>(T))'. • 30379.dart:11:9 • invalid_assignment
  error • A value of type 'int Function<T>(int Function<S>(T))' can't be assigned to a variable of type 'int Function<T>(int Function<Q>(Q))'. • 30379.dart:13:9 • invalid_assignment
4 errors found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants