Add tests for constructor tearoff as const function.
Also update some TODOs.
Change-Id: I02c883e717a3315892a99879ef45aba804183c86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212020
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index c4bf424..af1fa6f 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -1043,7 +1043,8 @@
} else if (operatorType == TokenType.TILDE_SLASH) {
return _dartObjectComputer.integerDivide(node, leftResult, rightResult);
} else {
- // TODO(brianwilkerson) Figure out which error to report.
+ // TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
+ // error code.
_error(node, null);
return null;
}
@@ -1108,7 +1109,8 @@
DartObjectImpl? visitInstanceCreationExpression(
InstanceCreationExpression node) {
if (!node.isConst) {
- // TODO(brianwilkerson) Figure out which error to report.
+ // TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
+ // error code.
_error(node, null);
return null;
}
@@ -1209,7 +1211,8 @@
}
}
}
- // TODO(brianwilkerson) Figure out which error to report.
+ // TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
+ // error code.
_error(node, null);
return null;
}
@@ -1220,7 +1223,8 @@
@override
DartObjectImpl? visitNode(AstNode node) {
- // TODO(brianwilkerson) Figure out which error to report.
+ // TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
+ // error code.
_error(node, null);
return null;
}
@@ -1274,7 +1278,8 @@
} else if (node.operator.type == TokenType.MINUS) {
return _dartObjectComputer.negated(node, operand);
} else {
- // TODO(brianwilkerson) Figure out which error to report.
+ // TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
+ // error code.
_error(node, null);
return null;
}
@@ -1655,7 +1660,8 @@
// Constants may not refer to type parameters.
}
- // TODO(brianwilkerson) Figure out which error to report.
+ // TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
+ // error code.
_error(node, null);
return null;
}
diff --git a/pkg/analyzer/test/generated/constant_test.dart b/pkg/analyzer/test/generated/constant_test.dart
index f97d66a..4920947 100644
--- a/pkg/analyzer/test/generated/constant_test.dart
+++ b/pkg/analyzer/test/generated/constant_test.dart
@@ -126,6 +126,50 @@
assertType(value.type, 'C');
}
+ test_constructorReference_generic_named() async {
+ var result = await _getExpressionValue("C<int>.foo", context: '''
+class C<T> {
+ C.foo();
+}
+''');
+ expect(result.isValid, isTrue);
+ DartObject value = result.value!;
+ assertType(value.type, 'C<int> Function()');
+ }
+
+ test_constructorReference_generic_unnamed() async {
+ var result = await _getExpressionValue("C<int>.new", context: '''
+class C<T> {
+ C.new();
+}
+''');
+ expect(result.isValid, isTrue);
+ DartObject value = result.value!;
+ assertType(value.type, 'C<int> Function()');
+ }
+
+ test_constructorReference_nonGeneric_named() async {
+ var result = await _getExpressionValue("C.foo", context: '''
+class C {
+ const C.foo();
+}
+''');
+ expect(result.isValid, isTrue);
+ DartObject value = result.value!;
+ assertType(value.type, 'C Function()');
+ }
+
+ test_constructorReference_nonGeneric_unnamed() async {
+ var result = await _getExpressionValue("C.new", context: '''
+class C {
+ const C();
+}
+''');
+ expect(result.isValid, isTrue);
+ DartObject value = result.value!;
+ assertType(value.type, 'C Function()');
+ }
+
test_divide_double_double() async {
await _assertValueDouble(3.2 / 2.3, "3.2 / 2.3");
}
diff --git a/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart b/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart
index 00b6b27..499d93f 100644
--- a/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart
@@ -23,7 +23,7 @@
test_alias_generic_const() async {
await assertNoErrorsInCode('''
class A<T, U> {
- A.foo();
+ const A.foo();
}
typedef TA<T, U> = A<U, T>;