Skip to content

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

Closed
@iarkh

Description

@iarkh

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NNBDIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions