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

NNBD: I-2-b works in different ways in analyzer and dart for the function with unused type parameter. #41684

Closed
iarkh opened this issue Apr 28, 2020 · 4 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@iarkh
Copy link
Contributor

iarkh commented Apr 28, 2020

Dart VM version: 2.9.0-3.0.dev (dev) (Thu Apr 23 09:59:01 2020 +0200) on "windows_x64"

The following source code causes a compile error in analyzer and runtime error in dart:

typedef F<X> = void Function<Y extends X>();

F<X> toF<X>(X x) => throw "It's runtime!";
Type typeOf<X>() => X;

typedef G<X extends num> = void Function();

main() {
  G? source;
  var fsource = toF(source);
  F<G<num>?>? target1 = fsource;
  F<G<Object>?>? target2 = fsource;
}

It seems like both tools should behave in a similar way here.

Sample output is:

$> dartanalyzer --enable-experiment=non-nullable test.dart
Analyzing test.dart...
error - 'Object' doesn't extend 'num'. - test.dart:12:7 - type_argument_not_matching_bounds
hint - The value of the local variable 'target1' isn't used. - test.dart:11:15 - unused_local_variable
hint - The value of the local variable 'target2' isn't used. - test.dart:12:18 - unused_local_variable
1 error and 2 hints found.

$> dart --enable-experiment=non-nullable test.dart
Unhandled exception:
It's runtime!
#0 toF (file:///D:/DART/sdk/tests/co19/src/LanguageFeatures/Simple-bounds/static/test.dart:3:21)
#1 main (file:///D:/DART/sdk/tests/co19/src/LanguageFeatures/Simple-bounds/static/test.dart:10:17)
#2 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

@mraleph mraleph added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Apr 28, 2020
@mraleph
Copy link
Member

mraleph commented Apr 28, 2020

Looks like a missing compile time error in the CFE

/cc @johnniwinther @stefantsov

@mraleph mraleph added the NNBD Issues related to NNBD Release label Apr 28, 2020
@johnniwinther
Copy link
Member

This is triggering a latent bug in the CFE and is not a priority for Null Safety Tech Preview.

@leafpetersen
Copy link
Member

Should this be separated from the null safety release or do we want to have this fixed for stable.

@franklinyow franklinyow added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Sep 3, 2020
@eernstg
Copy link
Member

eernstg commented Sep 4, 2020

The analyzer treats the unused type variable as if it were covariant (which is also what is proposed in this PR). So there's an error with G<Object> because that's a bound violation and not a correct super-bounded type, but G<Object?> is accepted. All good.

For the CFE it looks like it hasn't been updated to use Object? rather than Object when it checks whether a given substitution should be performed during the check for being a correct super-bounded type. I would expect that to be needed as part of the null-safety release. That's addressed directly by #42429.

I think that makes this issue a duplicate of #42429, and I'll close this one because #42429 addresses the remaining issue more directly.

@eernstg eernstg closed this as completed Sep 4, 2020
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. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants