Skip to content

Type inference doesn't work nicely with function types #30822

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
floitschG opened this issue Sep 20, 2017 · 4 comments
Closed

Type inference doesn't work nicely with function types #30822

floitschG opened this issue Sep 20, 2017 · 4 comments
Labels
closed-duplicate Closed in favor of an existing report language-strong-mode-polish legacy-area-analyzer Use area-devexp instead.

Comments

@floitschG
Copy link
Contributor

floitschG commented Sep 20, 2017

/cc @leafpetersen

I just ran into the following bug in the type inference:

// Wants a function that takes a function and returns a same-typed function.
void foo(T Function() Function<T>(T Function() f) parameterName) {}

// Using a function literal. -> the return type needs to be inferred.
foo(<T>(T Function() f) {
  if (true) return f;
  return () => f();
});

Clearly, the return type of the function literal is T Function().
Removing either return makes the whole thing work. But having both at the same time leads to an error.

@floitschG floitschG added the legacy-area-analyzer Use area-devexp instead. label Sep 20, 2017
@lrhn
Copy link
Member

lrhn commented Sep 20, 2017

A runnable example: https://dartpad.dartlang.org/43bb3ebec177b1008f5c9308b53f5959
The error message that you get is the cryptic:

The argument type '<T₀>(() → T₀) → () → T' can't be assigned to the parameter type '<T>(() → T) → () → T'.

(But you do get bonus points for the non-ASCII chars, it's looking good!)

@leafpetersen
Copy link
Member

Simplified example, that also changes the type variable name to check that it's not a dup of #30379:

main() {
  T Function() Function<T>() g =
      <S>() {
    S Function() f;
    if (f != null) return f;
    return () => f();
  };
}

@jmesserly
Copy link

possibly related bug: #29778 (comment)

@jmesserly jmesserly added the closed-duplicate Closed in favor of an existing report label Sep 22, 2017
@jmesserly
Copy link

Looking at this more, I'm pretty sure it's a dupe of #29778. I'll make sure these test cases are over there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report language-strong-mode-polish legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

4 participants