Skip to content

I-2-b: Dart does not throw a compile error if non-function type alias type argument does not conform to the bound. #44223

Closed
@iarkh

Description

@iarkh

Dart SDK version: 2.12.0-33.0.dev (dev) (Wed Nov 11 17:34:11 2020 -0800) on "windows_x64"

Here is a sample code example:

class C<X> {}
typedef A<X extends C<X>> = C<X>;

class C1<X extends C1<X>> {}

void main() {
  A();
  C1();
}

It seems like both A() and C1() calls should throw compile errors because type argument does not conform to the bound in both cases.

However it does not happen for the non-function type alias, A() call just passes.

Sample output is:

$> dart --enable-experiment=nonfunction-type-aliases test.dart
test.dart:8:3: Error: Inferred type argument 'C1<Object?>' doesn't conform to the bound 'C1<X>' of the type variable 'X' on 'C1'.
 - 'C1' is from 'test.dart'.
 - 'Object' is from 'dart:core'.
Try specifying type arguments explicitly so that they conform to the bounds.
  C1();
  ^
test.dart:4:10: Context: This is the type variable whose bound isn't conformed to.
class C1<X extends C1<X>> {}
         ^

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions