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

Incorrect downwards type inference in CFE #43536

Closed
munificent opened this issue Sep 23, 2020 · 3 comments
Closed

Incorrect downwards type inference in CFE #43536

munificent opened this issue Sep 23, 2020 · 3 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. customer-google3 NNBD Issues related to NNBD Release

Comments

@munificent
Copy link
Member

munificent commented Sep 23, 2020

OK, I believe CFE is doing the wrong thing here, but it's in a corner of type inference I don't understand well, so I could be wrong. For what it's worth, analyzer does not report an error on the same code, so one of our tools is wrong:

class C<T> {
  foo<E extends T>(List<E> list) {
    List<E> variable = method(list);
  }

  List<F> method<F extends T>(List<F> list) => list;
}

In CFE, this produces:

../../../Documents/temp.dart:3:31: Error: The argument type 'List<E>' can't be assigned to the parameter type 'List<Never>'.
 - 'List' is from 'dart:core'.
    List<E> variable = method(list);

It looks like CFE is inferring List<Never> from the downwards inference (I'm guessing by taking the greatest/least closure to eliminate the inferred E extends T and only after that is done looking at the parameter's type.

@leafpetersen @matanlurey

@munificent munificent added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Sep 23, 2020
@matanlurey matanlurey added customer-google3 NNBD Issues related to NNBD Release labels Sep 24, 2020
@matanlurey
Copy link
Contributor

Worth mentioning: This did not occur prior to null-safety opt-in.

@leafpetersen
Copy link
Member

Yeah, this looks like a bug to me. We're inferring the call method(list) in context List<E>. That implies a downwards inference constraint solve of List<F> <# List<E> solving for F. That reduces to F <# E solving for F, which produces the constraint _ <: F <: E. With no further constraints, we should fix F to be E. That's a valid solution, so there should be no further issues

@johnniwinther
Copy link
Member

@stefantsov Can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. customer-google3 NNBD Issues related to NNBD Release
Projects
None yet
Development

No branches or pull requests

5 participants