mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:10:22 +00:00
Extension types. Report an error if the feature is not enabled.
Change-Id: Icc1e4fddea91dab22fcab694928c9138b0781e76 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318440 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
8cb82a35e8
commit
b9a66a0d2e
2 changed files with 44 additions and 9 deletions
|
@ -1658,15 +1658,22 @@ class AstBuilder extends StackListener {
|
|||
final representation = pop() as RepresentationDeclarationImpl;
|
||||
final constKeyword = pop() as Token?;
|
||||
|
||||
final builder = _classLikeBuilder as _ExtensionTypeDeclarationBuilder;
|
||||
declarations.add(
|
||||
builder.build(
|
||||
typeKeyword: typeKeyword,
|
||||
constKeyword: constKeyword,
|
||||
representation: representation,
|
||||
implementsClause: implementsClause,
|
||||
),
|
||||
);
|
||||
if (enableInlineClass) {
|
||||
final builder = _classLikeBuilder as _ExtensionTypeDeclarationBuilder;
|
||||
declarations.add(
|
||||
builder.build(
|
||||
typeKeyword: typeKeyword,
|
||||
constKeyword: constKeyword,
|
||||
representation: representation,
|
||||
implementsClause: implementsClause,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
_reportFeatureNotEnabled(
|
||||
feature: ExperimentalFeatures.inline_class,
|
||||
startToken: typeKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
_classLikeBuilder = null;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,34 @@ ExtensionTypeDeclaration
|
|||
''');
|
||||
}
|
||||
|
||||
test_featureNotEnabled() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
// @dart = 3.1
|
||||
class A {}
|
||||
extension type B(int it) {}
|
||||
class C {}
|
||||
''');
|
||||
parseResult.assertErrors([
|
||||
error(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 36, 4),
|
||||
]);
|
||||
|
||||
final node = parseResult.findNode.unit;
|
||||
assertParsedNodeText(node, r'''
|
||||
CompilationUnit
|
||||
declarations
|
||||
ClassDeclaration
|
||||
classKeyword: class
|
||||
name: A
|
||||
leftBracket: {
|
||||
rightBracket: }
|
||||
ClassDeclaration
|
||||
classKeyword: class
|
||||
name: C
|
||||
leftBracket: {
|
||||
rightBracket: }
|
||||
''');
|
||||
}
|
||||
|
||||
test_field_metadata() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(@foo int it) {}
|
||||
|
|
Loading…
Reference in a new issue