Skip to content

Unexpected compile error during the generic non-function type alias object creation #42432

@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 example calls generic type alias constructor without type parameter specified:

class C<T> {}
typedef CAlias<T extends num> = C<T>;

main() {
  CAlias ca1 = new CAlias();
  print(ca1 is C<num>);
}

Seems like dart should print true, however it throws a compile error instead.

Sample output is:

$> dart --enable-experiment=nonfunction-type-aliases test.dart
test.dart:5:20: Error: The constructor returns type 'C' that isn't of expected type 'C'.

  • 'C' is from 'test.dart'.
    Change the type of the object being constructed or the context in which it is used.
    CAlias ca1 = new CAlias();
    ^

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions