Skip to content

Commit

Permalink
fix extension abstract method error
Browse files Browse the repository at this point in the history
This changes EXTENSION_DECLARES_ABSTRACT_MEMBER to be a parse error
and moves it into the parser so that it is generated for all of CFE.

Fix dart-lang/sdk#37945

Change-Id: Iba2876eb2db83e96ec49adc49a7b6a0e7aff200b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116002
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
danrubel authored and commit-bot@chromium.org committed Sep 6, 2019
1 parent a689f8d commit 4e4047a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/error/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const List<ErrorCode> errorCodeValues = const [
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS,
CompileTimeErrorCode.EXTENDS_NON_CLASS,
CompileTimeErrorCode.EXTENSION_CONFLICTING_STATIC_AND_INSTANCE,
CompileTimeErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER,
CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT,
CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER,
CompileTimeErrorCode.EXTENSION_OVERRIDE_ARGUMENT_NOT_ASSIGNABLE,
Expand Down Expand Up @@ -463,6 +462,7 @@ const List<ErrorCode> errorCodeValues = const [
ParserErrorCode.EXPECTED_TYPE_NAME,
ParserErrorCode.EXPERIMENT_NOT_ENABLED,
ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE,
ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER,
ParserErrorCode.EXTENSION_DECLARES_CONSTRUCTOR,
ParserErrorCode.EXTENSION_DECLARES_INSTANCE_FIELD,
ParserErrorCode.EXTERNAL_AFTER_CONST,
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class ParserErrorCode extends ErrorCode {
static const ParserErrorCode EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE =
_EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE;

static const ParserErrorCode EXTENSION_DECLARES_ABSTRACT_MEMBER =
_EXTENSION_DECLARES_ABSTRACT_MEMBER;

static const ParserErrorCode EXTENSION_DECLARES_CONSTRUCTOR =
_EXTENSION_DECLARES_CONSTRUCTOR;

Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ final fastaAnalyzerErrorCodes = <ErrorCode>[
_ANNOTATION_WITH_TYPE_ARGUMENTS,
_EXTENSION_DECLARES_CONSTRUCTOR,
_EXTENSION_DECLARES_INSTANCE_FIELD,
_EXTENSION_DECLARES_ABSTRACT_MEMBER,
];

const ParserErrorCode _ABSTRACT_CLASS_MEMBER = const ParserErrorCode(
Expand Down Expand Up @@ -246,6 +247,11 @@ const ParserErrorCode _EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE =
correction:
"Try moving the export directives before the part directives.");

const ParserErrorCode _EXTENSION_DECLARES_ABSTRACT_MEMBER =
const ParserErrorCode('EXTENSION_DECLARES_ABSTRACT_MEMBER',
r"Extensions can't declare abstract members.",
correction: "Try providing an implementation for the member.");

const ParserErrorCode _EXTENSION_DECLARES_CONSTRUCTOR = const ParserErrorCode(
'EXTENSION_DECLARES_CONSTRUCTOR', r"Extensions can't declare constructors.",
correction: "Try removing the constructor declaration.");
Expand Down
8 changes: 0 additions & 8 deletions pkg/analyzer/lib/src/error/codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1295,14 +1295,6 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
correction:
"Try renaming the member to a name that doesn't conflict.");

/**
* No parameters.
*/
static const CompileTimeErrorCode EXTENSION_DECLARES_ABSTRACT_MEMBER =
const CompileTimeErrorCode('EXTENSION_DECLARES_ABSTRACT_MEMBER',
"Extensions can't declare abstract members.",
correction: "Try providing an implementation for the member.");

/**
* No parameters.
*/
Expand Down
6 changes: 0 additions & 6 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:analyzer/src/dart/ast/ast.dart'
CompilationUnitImpl,
ExtensionDeclarationImpl,
MixinDeclarationImpl;
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/fasta/error_converter.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
import 'package:front_end/src/fasta/messages.dart'
Expand Down Expand Up @@ -1604,11 +1603,6 @@ class AstBuilder extends StackListener {
messageConstMethod, modifiers.constKeyword, modifiers.constKeyword);
}
checkFieldFormalParameters(parameters);
if (extensionDeclaration != null && body is EmptyFunctionBody) {
errorReporter.errorReporter.reportErrorForNode(
CompileTimeErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, name);
return;
}
currentDeclarationMembers.add(ast.methodDeclaration(
comment,
metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

Expand All @@ -28,7 +28,7 @@ extension E on String {
bool get isPalindrome;
}
''', [
error(CompileTimeErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 35, 12),
error(ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 35, 12),
]);
}

Expand All @@ -38,7 +38,7 @@ extension E on String {
String reversed();
}
''', [
error(CompileTimeErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 33, 8),
error(ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 33, 8),
]);
}

Expand All @@ -54,7 +54,7 @@ extension E on String {
String operator -(String otherString);
}
''', [
error(CompileTimeErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 42, 1),
error(ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 42, 1),
]);
}

Expand All @@ -64,7 +64,7 @@ extension E on String {
set length(int newLength);
}
''', [
error(CompileTimeErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 30, 6),
error(ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER, 30, 6),
]);
}
}
11 changes: 11 additions & 0 deletions pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,17 @@ Message _withArgumentsExtendingRestricted(String name) {
arguments: {'name': name});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeExtensionDeclaresAbstractMember =
messageExtensionDeclaresAbstractMember;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageExtensionDeclaresAbstractMember = const MessageCode(
"ExtensionDeclaresAbstractMember",
index: 94,
message: r"""Extensions can't declare abstract members.""",
tip: r"""Try providing an implementation for the member.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeExtensionDeclaresConstructor =
messageExtensionDeclaresConstructor;
Expand Down
14 changes: 9 additions & 5 deletions pkg/front_end/lib/src/fasta/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3338,14 +3338,14 @@ class Parser {
if (getOrSet != null && !inPlainSync && optional("set", getOrSet)) {
reportRecoverableError(asyncToken, fasta.messageSetterNotSync);
}
Token next = token.next;
final Token bodyStart = token.next;
if (externalToken != null) {
if (!optional(';', next)) {
reportRecoverableError(next, fasta.messageExternalMethodWithBody);
if (!optional(';', bodyStart)) {
reportRecoverableError(bodyStart, fasta.messageExternalMethodWithBody);
}
}
if (optional('=', next)) {
reportRecoverableError(next, fasta.messageRedirectionInNonFactory);
if (optional('=', bodyStart)) {
reportRecoverableError(bodyStart, fasta.messageRedirectionInNonFactory);
token = parseRedirectingFactoryBody(token);
} else {
token = parseFunctionBody(token, false,
Expand Down Expand Up @@ -3407,6 +3407,10 @@ class Parser {
beforeInitializers?.next, token);
break;
case DeclarationKind.Extension:
if (optional(';', bodyStart)) {
reportRecoverableError(isOperator ? name.next : name,
fasta.messageExtensionDeclaresAbstractMember);
}
listener.endExtensionMethod(getOrSet, beforeStart.next,
beforeParam.next, beforeInitializers?.next, token);
break;
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/messages.status
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ ExternalConstructorWithFieldInitializers/example: Fail
ExternalFactoryRedirection/example: Fail
ExternalFactoryWithBody/part_wrapped_script1: Fail
ExternalFactoryWithBody/script1: Fail
ExtensionDeclaresAbstractMember/example: Fail
ExtensionDeclaresConstructor/example: Fail
ExtensionDeclaresInstanceField/example: Fail
ExtraneousModifier/part_wrapped_script1: Fail
Expand Down
6 changes: 6 additions & 0 deletions pkg/front_end/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,12 @@ IllegalMixinDueToConstructorsCause:
template: "This constructor prevents using '#name' as a mixin."
severity: CONTEXT

ExtensionDeclaresAbstractMember:
index: 94
template: "Extensions can't declare abstract members."
tip: "Try providing an implementation for the member."
analyzerCode: ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER

ExtensionDeclaresConstructor:
index: 92
template: "Extensions can't declare constructors."
Expand Down

0 comments on commit 4e4047a

Please sign in to comment.