Skip to content

CFE does not reject non-const partial instantiations for default parameter values #32912

Closed
@leafpetersen

Description

@leafpetersen

This is the CFE specific issue for the default parameter issue from #32415 .

Partial instantiations of generic methods are only const objects if their type arguments are const types. The CFE should statically reject the following program, but currently doesn't.

dynamic _defaultCallback<T>(T t) => t;
class C<T> {
  final dynamic Function(T) callback;
  // Should be statically rejected
  void foo([dynamic Function(T) f = _defaultCallback]) {}
  // Should be statically rejected
  const C({this.callback = _defaultCallback});
}

// Should be statically rejected
void bar<T>([dynamic Function(T) f = _defaultCallback]) {}

void main() {
  print(new C<int>().callback);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions