-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
Description
When using a constructor tearoff such as Foo.new or Foo.bar of a class with generic types in a const expression, the analyzer fails to produce an error message. The code is correctly rejected by the CFE, for example by using dart run.
Example:
class Foo<T> {}
Foo<T> defaultCreateFoo<T>() => Foo<T>();
void bar<T>({
// No analyzer error.
Foo<T> Function() createFoo = Foo.new,
}) {
// No analyzer error.
const Foo<T> Function() createFooVar1 = Foo.new;
// Correct analyzer error.
const Foo<T> Function() createFooVar2 = defaultCreateFoo;
// ^^^^^^^^^^^^^^^^
// A constant function tearoff can't use a type parameter as a type argument.
}
void main() {
bar();
}I tested this with Dart SDK 3.7.0-243.0.dev on https://dartpad.dev/?channel=main.
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)