mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
disallow literal extension type declarations
As per the discussion in https://github.com/dart-lang/sdk/issues/53508, this way of annotating primary constructors is ambiguous. Removing. Change-Id: I1425b95185ee05cfed953fd8b0b845a2ddd8b8f1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325802 Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
38f62d2159
commit
2f13f043d5
3 changed files with 10 additions and 41 deletions
|
@ -197,10 +197,6 @@ class AnnotationVerifier {
|
|||
/// `@literal` annotation.
|
||||
void _checkLiteral(AstNode node) {
|
||||
var parent = node.parent;
|
||||
// Primary constructor of an extension type declaration.
|
||||
if (parent is ExtensionTypeDeclaration && parent.constKeyword != null) {
|
||||
return;
|
||||
}
|
||||
if (parent is! ConstructorDeclaration || parent.constKeyword == null) {
|
||||
_errorReporter
|
||||
.reportErrorForNode(WarningCode.INVALID_LITERAL_ANNOTATION, node, []);
|
||||
|
|
|
@ -41,12 +41,14 @@ extension type const E(int i) {
|
|||
''');
|
||||
}
|
||||
|
||||
test_extensionType_primaryConstructor_const() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
test_extensionType_declaration() async {
|
||||
await assertErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@literal
|
||||
extension type const E(int i) { }
|
||||
''');
|
||||
''', [
|
||||
error(WarningCode.INVALID_LITERAL_ANNOTATION, 33, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
test_nonConstConstructor() async {
|
||||
|
|
|
@ -42,15 +42,6 @@ const a = A();
|
|||
''');
|
||||
}
|
||||
|
||||
test_constContextCreation_extensionType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@literal
|
||||
extension type const E(int i) { }
|
||||
const e = E(1);
|
||||
''');
|
||||
}
|
||||
|
||||
test_constCreation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
@ -65,9 +56,11 @@ const a = const A();
|
|||
test_constCreation_extensionType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@literal
|
||||
extension type const E(int i) { }
|
||||
const e = const E(1);
|
||||
extension type const E(int i) {
|
||||
@literal
|
||||
const E.zero(): this(0);
|
||||
}
|
||||
E e = const E.zero();
|
||||
''');
|
||||
}
|
||||
|
||||
|
@ -133,26 +126,4 @@ E e = E.zero();
|
|||
error(WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR, 112, 8),
|
||||
]);
|
||||
}
|
||||
|
||||
test_usingNew_extensionType_nonConst() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@literal
|
||||
extension type const E(int i) {
|
||||
E.zero(): this(0);
|
||||
}
|
||||
E e = E.zero();
|
||||
''');
|
||||
}
|
||||
|
||||
test_usingNew_extensionType_primaryConstructor() async {
|
||||
await assertErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
@literal
|
||||
extension type const E(int i) { }
|
||||
E e = E(1);
|
||||
''', [
|
||||
error(WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR, 82, 4),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue