Skip to content

Generic function types used as variable declarations are misinterpreted #29237

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
leafpetersen opened this issue Apr 4, 2017 · 14 comments
Closed
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@leafpetersen
Copy link
Member

The code below should have no errors, but on bleeding edge shows an error on the call to y.

It looks to me as if perhaps the variable declaration Foo y is being interpreted as declaring y to have type T -> int with T unbound, instead of <T>(T) -> int.

Analyzing /Users/leafp/tmp/test.dart...
    error • The method '(T) → int' is declared with 0 type parameters, but 1 type arguments were given at /Users/leafp/tmp/test.dart:21:3 • wrong_number_of_type_arguments_method
    error • The argument type 'String' can't be assigned to the parameter type 'T' at /Users/leafp/tmp/test.dart:21:13 • argument_type_not_assignable
typedef Foo = int Function<T>(T x);
int foo<T>(T x) => 3;
void test1() {
  Foo y = foo;
  // These two should be equivalent
  foo<String>("hello");
  y<String>("hello"); // error here
}
@jmesserly
Copy link

My guess for this bug and #29236 is that the "typedef Foo" is not creating a FunctionTypeImpl that is generic (type.typeFormals.isNotEmpty). It's possible it's being treated as equivalent to typedef in Foo<T>(T x);

@mit-mit
Copy link
Member

mit-mit commented Apr 4, 2017

Should this be 1.23 @kevmoo ?

@leafpetersen
Copy link
Member Author

My take is that this is pretty much the core of analyzer support for generic function types, so either we push the feature off, or this bug is 1.23. Marking it 1.23 now, since the feature is currently still marked 1.23.

@leafpetersen leafpetersen added this to the 1.23 milestone Apr 4, 2017
@dgrove
Copy link
Contributor

dgrove commented Apr 4, 2017

@bwilkerson can you please take a look ASAP?

@leafpetersen
Copy link
Member Author

I think Brian is out, I'm taking a look now to see if I can make some progress on it.

@jmesserly
Copy link

Awesome! Let me know if I can help at all.

@bwilkerson
Copy link
Member

@leafpetersen
Copy link
Member Author

I think this is still broken for return types and fields (at least).

typedef Foo = int Function<T>(T x);
int foo<T>(T x) => 3;
Foo bar() => foo;
void test1() {
  bar()<String>("hello");
}

class A {
  Foo f;
  void test() {
    f<String>("hello");
  }
}
Analyzing /Users/leafp/tmp/test.dart...
    error • The method '(T) → int' is declared with 0 type parameters, but 1 type arguments were given at /Users/leafp/tmp/test.dart:5:3 • wrong_number_of_type_arguments_method
    error • The argument type 'String' can't be assigned to the parameter type 'T' at /Users/leafp/tmp/test.dart:5:17 • argument_type_not_assignable
    error • The method '(T) → int' is declared with 0 type parameters, but 1 type arguments were given at /Users/leafp/tmp/test.dart:11:5 • wrong_number_of_type_arguments_method
    error • The argument type 'String' can't be assigned to the parameter type 'T' at /Users/leafp/tmp/test.dart:11:15 • argument_type_not_assignable
4 errors found.

@leafpetersen leafpetersen reopened this Apr 5, 2017
@bwilkerson bwilkerson added P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 10, 2017
@scheglov
Copy link
Contributor

scheglov added a commit that referenced this issue Apr 11, 2017
…r resynthesizing.

This is based on your CL https://codereview.chromium.org/2808093004/ and
includes fixes for summarization and resynthesis.

[email protected]
BUG= #29237

Review-Url: https://codereview.chromium.org/2814443005 .
@jmesserly
Copy link

I think this CL landed so we can close the bug out ... feel free to reopen if there's more to it!

@devoncarew
Copy link
Member

@scheglov, does your commit still need to be merged into 1.23 stable?

@scheglov
Copy link
Contributor

scheglov commented Apr 12, 2017

It does, but that's not the end yet :-(
Brian and I found at least three other problems with generic functions, while running Florian's test suite.

@jmesserly
Copy link

I found one in DDC too, so you're not alone :)

@bwilkerson
Copy link
Member

@jmesserly Just FYI: there was a commit this morning that fixed the last known problem in the parser. That might well have caused follow-on issues in DDC, so you should re-test. The summary work that Konstantin is doing might also be causing problems for DDC, so you might need to wait for his work before you can be sure of the status of DDC.

whesse pushed a commit that referenced this issue Apr 15, 2017
…r resynthesizing.

This is based on your CL https://codereview.chromium.org/2808093004/ and
includes fixes for summarization and resynthesis.

[email protected]
BUG= #29237

Review-Url: https://codereview.chromium.org/2814443005 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants