Skip to content

GLB/LUB do not handle generic functions #30237

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
jmesserly opened this issue Jul 22, 2017 · 4 comments
Closed

GLB/LUB do not handle generic functions #30237

jmesserly opened this issue Jul 22, 2017 · 4 comments
Labels
dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec language-strong-mode-polish legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on soundness type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jmesserly
Copy link

for example:

void main() {
  var isEven = new DateTime.now().millisecond.isEven;
  var f = isEven ? <T>(T t) => t : <U>(U t) => t;
  print(f<int>(42)); // The method '(<bottom>) → Object' is declared with 0 type parameters, but 1 type arguments were given
}

even worse:

void main() {
  var isEven = new DateTime.now().millisecond.isEven;
  var f = isEven ? <T>() => 42 : <U>() => 42;
  print(f());
}

prints the internal closure used for generic method dispatch (this function object should never be exposed to user code):

Closure: NativeJavaScriptObject from: () => {
    return 42;
  }
@jmesserly jmesserly self-assigned this Jul 22, 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 Jul 25, 2017
@jmesserly jmesserly removed their assignment Oct 4, 2017
@jmesserly
Copy link
Author

this was fixed, yay!

@scheglov
Copy link
Contributor

This still fails.

typedef F1 = T Function<T>();
typedef F2 = U Function<U>();

main() {
  F1 a;
  F2 b;
  F1 c = a ?? b;
}

error: A value of type '() → Object' can't be assigned to a variable of type '<T>() → T'. (invalid_assignment at [test] bin/test.dart:7)

But when I change both a and b to be either F1 or F2, then their types become identical objects, and returned from getLeastUpperBound(t1, t2) as t1, which does have type parameters.

Found this while working on a change for nullability, which we don't check yet, but we get non-identical FunctionType instances, so don't take the shortcut.

@scheglov scheglov reopened this Jan 14, 2019
@jmesserly
Copy link
Author

Yeah, wow, _functionLeastUpperBound does not handle generic functions at all, same for GLB. (Not sure why I thought it was fixed, oops!)

@srawlins srawlins added the dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 17, 2020
@srawlins
Copy link
Member

This appears to be fixed. Also the follow up example, when modified for null safety:

typedef F1 = T Function<T>();
typedef F2 = U Function<U>();

f(F1? a, F2, b) {
  F1 c = a ?? b;
}

is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec language-strong-mode-polish legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on soundness type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants