Skip to content

NNBD: Unexpected unhandled exception during the generic contravariant function variable assigning  #42433

@iarkh

Description

@iarkh

Dart VM version: 2.9.0-17.0.dev (dev) (Thu Jun 18 10:22:39 2020 +0200) on "windows_x64"

The following source code throws unexpected unhandled error when assign generic contravariant function variable:

class X {}

checkme<T extends X>(T? t) {}
typedef Test<T extends X>(T? t);

main() {
  Test<X> t2 = checkme;
}

Sample output is:

$> dart --enable-experiment=nonfunction-type-aliases,non-nullable test.dart
Unhandled exception:
type 'X?' is not a subtype of type 'X' of 'T'
#0 _boundsCheckForPartialInstantiation (dart:_internal-patch/internal_patch.dart:146:57)
#1 main (file:///D:/DART/sdk/tests/co19/src/Language/Generics/test.dart)
#2 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Please note that dart passes with covariant case, i.e. the following source example passes:

class X {}

T? checkme<T extends X>() {}
typedef T? Test<T extends X>();

main() {
  Test<X> t2 = checkme;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NNBDIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions