mirror of
https://github.com/dart-lang/sdk
synced 2024-09-20 23:41:18 +00:00
Allow any type parameter as a potentially const expression
Bug: https://github.com/dart-lang/sdk/issues/46020 Fixes language/const/instantiated_function_constant_test Change-Id: I7b9a92a7abca213919d0850dd68c5b2d3d4857f5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216601 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
20da76f9f8
commit
cebf84d729
|
@ -380,14 +380,10 @@ class _ConstantTypeChecker {
|
|||
|
||||
/// Return `true` if the [node] is a (potentially) constant type expression.
|
||||
bool check(TypeAnnotation? node) {
|
||||
if (potentially) {
|
||||
if (node is NamedType) {
|
||||
var element = node.name.staticElement;
|
||||
if (element is TypeParameterElement) {
|
||||
var enclosing = element.enclosingElement;
|
||||
return enclosing is ClassElement && !enclosing.isMixin;
|
||||
}
|
||||
}
|
||||
if (potentially &&
|
||||
node is NamedType &&
|
||||
node.name.staticElement is TypeParameterElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node is NamedType) {
|
||||
|
|
|
@ -118,42 +118,25 @@ class A<T> {
|
|||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_ofExtension() async {
|
||||
await _assertNeverConst(r'''
|
||||
extension E<T> on int {
|
||||
void foo() {
|
||||
T x;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_ofFunction() async {
|
||||
await _assertNeverConst(r'''
|
||||
await _assertPotentiallyConst('''
|
||||
void foo<T>() {
|
||||
T x;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_ofMethod() async {
|
||||
await _assertNeverConst(r'''
|
||||
class A {
|
||||
void foo<T>() {
|
||||
T x;
|
||||
test_typeParameter_ofFunctionType() async {
|
||||
await _assertPotentiallyConst('''
|
||||
class A<U> {
|
||||
const A();
|
||||
void foo() {
|
||||
void Function<X>(X) x;
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_typeParameter_ofMixin() async {
|
||||
await _assertNeverConst(r'''
|
||||
mixin M<T> {
|
||||
T x;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_void() async {
|
||||
await _assertConst(r'''
|
||||
void x;
|
||||
|
|
Loading…
Reference in a new issue