Skip to content

Commit

Permalink
Rename several error codes and improve some messages
Browse files Browse the repository at this point in the history
Change-Id: I6e629719dee14c2af7c1358145fb25b21f5d5157
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114160
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
bwilkerson authored and commit-bot@chromium.org committed Aug 22, 2019
1 parent a35f4ec commit 5935b91
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 84 deletions.
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/error/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const List<ErrorCode> errorCodeValues = const [
CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE,
CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD,
CompileTimeErrorCode.AMBIGUOUS_EXPORT,
CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS,
CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS,
CompileTimeErrorCode.AMBIGUOUS_SET_OR_MAP_LITERAL_BOTH,
CompileTimeErrorCode.AMBIGUOUS_SET_OR_MAP_LITERAL_EITHER,
CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS,
Expand Down Expand Up @@ -245,7 +245,7 @@ const List<ErrorCode> errorCodeValues = const [
CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
CompileTimeErrorCode.NON_SYNC_FACTORY,
CompileTimeErrorCode.NOT_ASSIGNED_POTENTIALLY_NON_NULLABLE_LOCAL_VARIABLE,
CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS,
CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS,
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD,
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD_CONSTRUCTOR,
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_VARIABLE,
Expand Down
6 changes: 3 additions & 3 deletions pkg/analyzer/lib/src/dart/error/hint_codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,9 @@ class HintCode extends ErrorCode {
*/
static const HintCode SDK_VERSION_UI_AS_CODE_IN_CONST_CONTEXT = const HintCode(
'SDK_VERSION_UI_AS_CODE_IN_CONST_CONTEXT',
"The for, if and spread elements were not supported in const contexts "
"until version 2.5.0, but this code is required to be able to run on "
"earlier versions.",
"The for, if and spread elements weren't supported in constant "
"expressions until version 2.5.0, but this code is required to be "
"able to run on earlier versions.",
correction: "Try updating the SDK constraints.");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ExtensionMemberResolver {
}

_errorReporter.reportErrorForNode(
CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS,
CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS,
target,
[
name,
Expand Down
29 changes: 8 additions & 21 deletions pkg/analyzer/lib/src/error/codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ class CompileTimeErrorCode extends ErrorCode {
* 1: the name of the first declaring extension
* 2: the name of the second declaring extension
*/
static const CompileTimeErrorCode AMBIGUOUS_EXTENSION_METHOD_ACCESS =
static const CompileTimeErrorCode AMBIGUOUS_EXTENSION_MEMBER_ACCESS =
const CompileTimeErrorCode(
'AMBIGUOUS_EXTENSION_METHOD_ACCESS',
'AMBIGUOUS_EXTENSION_MEMBER_ACCESS',
"A member named '{0}' is defined in extensions '{1}' and '{2}' and "
"neither is more specific.",
correction:
Expand Down Expand Up @@ -1366,8 +1366,6 @@ class CompileTimeErrorCode extends ErrorCode {
* Parameters:
* 0: the maximum number of positional arguments
* 1: the actual number of positional arguments given
*
* See [NOT_ENOUGH_REQUIRED_ARGUMENTS].
*/
static const CompileTimeErrorCode EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED =
const CompileTimeErrorCode('EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED',
Expand Down Expand Up @@ -1528,9 +1526,10 @@ class CompileTimeErrorCode extends ErrorCode {
*/
static const CompileTimeErrorCode IMPLEMENTS_NON_CLASS =
const CompileTimeErrorCode('IMPLEMENTS_NON_CLASS',
"Classes and mixins can only implement classes.",
"Classes and mixins can only implement other classes and mixins.",
correction:
"Try specifying a class, or remove the name from the list.");
"Try specifying a class or mixin, or remove the name from the "
"list.");

/**
* 10.10 Superinterfaces: It is a compile-time error if two elements in the
Expand Down Expand Up @@ -2666,19 +2665,13 @@ class CompileTimeErrorCode extends ErrorCode {
"or mark it 'late'.");

/**
* 12.14.2 Binding Actuals to Formals: It is a static warning if <i>m < h</i>
* or if <i>m > n</i>.
*
* 16.12.2 Const: It is a compile-time error if evaluation of a constant
* object results in an uncaught exception being thrown.
*
* Parameters:
* 0: the expected number of required arguments
* 1: the actual number of positional arguments given
*/
static const CompileTimeErrorCode NOT_ENOUGH_REQUIRED_ARGUMENTS =
const CompileTimeErrorCode('NOT_ENOUGH_REQUIRED_ARGUMENTS',
"{0} required argument(s) expected, but {1} found.",
static const CompileTimeErrorCode NOT_ENOUGH_POSITIONAL_ARGUMENTS =
const CompileTimeErrorCode('NOT_ENOUGH_POSITIONAL_ARGUMENTS',
"{0} positional argument(s) expected, but {1} found.",
correction: "Try adding the missing arguments.");

/**
Expand Down Expand Up @@ -4596,8 +4589,6 @@ class StaticWarningCode extends ErrorCode {
* Parameters:
* 0: the maximum number of positional arguments
* 1: the actual number of positional arguments given
*
* See [NOT_ENOUGH_REQUIRED_ARGUMENTS].
*/
static const StaticWarningCode EXTRA_POSITIONAL_ARGUMENTS =
const StaticWarningCode('EXTRA_POSITIONAL_ARGUMENTS',
Expand All @@ -4611,8 +4602,6 @@ class StaticWarningCode extends ErrorCode {
* Parameters:
* 0: the maximum number of positional arguments
* 1: the actual number of positional arguments given
*
* See [NOT_ENOUGH_REQUIRED_ARGUMENTS].
*/
static const StaticWarningCode EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED =
const StaticWarningCode('EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED',
Expand Down Expand Up @@ -5214,8 +5203,6 @@ class StaticWarningCode extends ErrorCode {
* Parameters:
* 0: the expected number of required arguments
* 1: the actual number of positional arguments given
*
* See [EXTRA_POSITIONAL_ARGUMENTS].
*/
static const StaticWarningCode NOT_ENOUGH_REQUIRED_ARGUMENTS =
const StaticWarningCode('NOT_ENOUGH_REQUIRED_ARGUMENTS',
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5064,7 +5064,7 @@ class ResolverVisitor extends ScopedVisitor {
}
if (positionalArgumentCount < requiredParameterCount && noBlankArguments) {
ErrorCode errorCode = (reportAsError
? CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS
? CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS
: StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS);
if (onError != null) {
onError(errorCode, argumentList,
Expand Down
6 changes: 3 additions & 3 deletions pkg/analyzer/test/generated/compile_time_error_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,7 @@ main() {
const A();
}
''', [
error(CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, 48, 2),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 48, 2),
]);
}

Expand All @@ -3748,7 +3748,7 @@ class B extends A {
const B() : super();
}
''', [
error(CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, 69, 2),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 69, 2),
]);
}

Expand Down Expand Up @@ -4739,7 +4739,7 @@ var s5 = const Symbol('x', foo: 'x');
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 9, 17),
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 37, 15),
error(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 50, 1),
error(CompileTimeErrorCode.NOT_ENOUGH_REQUIRED_ARGUMENTS, 75, 2),
error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS, 75, 2),
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 100, 10),
error(CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER, 139, 3),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ f(Object o, A a, B b) {
o.a;
}
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 68, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 68, 1),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import '../dart/resolution/driver_resolution.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(AmbiguousExtensionMethodAccessTest);
defineReflectiveTests(AmbiguousExtensionMemberAccessTest);
});
}

@reflectiveTest
class AmbiguousExtensionMethodAccessTest extends DriverResolutionTest {
class AmbiguousExtensionMemberAccessTest extends DriverResolutionTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = new FeatureSet.forTesting(
Expand All @@ -36,7 +36,7 @@ extension E2 on A {
int f(A a) => a();
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 110, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 110, 1),
]);
}

Expand All @@ -56,7 +56,7 @@ f(A a) {
a.a;
}
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 109, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 109, 1),
]);
}

Expand All @@ -76,7 +76,7 @@ f(A a) {
a.a();
}
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 99, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 99, 1),
]);
}

Expand All @@ -95,7 +95,7 @@ extension E2 on A {
A f(A a) => a + a;
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 122, 5),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 122, 5),
]);
}

Expand All @@ -113,7 +113,7 @@ extension E2 on A {
int f(A a) => a[0];
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 134, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 134, 1),
]);
}

Expand All @@ -131,7 +131,7 @@ extension E2 on A {
int f(A a) => -a;
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 123, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 123, 1),
]);
}

Expand All @@ -151,7 +151,7 @@ f(A a) {
a.a = 3;
}
''', [
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_METHOD_ACCESS, 99, 1),
error(CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS, 99, 1),
]);
}
}
6 changes: 3 additions & 3 deletions pkg/analyzer/test/src/diagnostics/test_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'ambiguous_export_test.dart' as ambiguous_export;
import 'ambiguous_extension_method_access_test.dart'
as ambiguous_extension_method_access;
import 'ambiguous_extension_member_access_test.dart'
as ambiguous_extension_member_access;
import 'ambiguous_import_test.dart' as ambiguous_import;
import 'ambiguous_set_or_map_literal_test.dart' as ambiguous_set_or_map_literal;
import 'argument_type_not_assignable_test.dart' as argument_type_not_assignable;
Expand Down Expand Up @@ -301,7 +301,7 @@ import 'wrong_type_parameter_variance_in_superinterface_test.dart'
main() {
defineReflectiveSuite(() {
ambiguous_export.main();
ambiguous_extension_method_access.main();
ambiguous_extension_member_access.main();
ambiguous_import.main();
ambiguous_set_or_map_literal.main();
argument_type_not_assignable.main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ extension MyExt on A {
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t0);
bool t1 = this.getterInGlobalScope;
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t1);
this.setterInGlobalScope = extensionValue;
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
bool t2 = this.methodInGlobalScope();
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t2);
}

Expand Down Expand Up @@ -143,24 +143,24 @@ extension MyExt on A {
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t0);
bool t1 = self.getterInGlobalScope;
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t1);
self.setterInGlobalScope = extensionValue;
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
bool t2 = self.methodInGlobalScope();
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t2);
}

Expand Down Expand Up @@ -232,24 +232,24 @@ void main() {
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t0);
bool t1 = a.getterInGlobalScope;
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t1);
a.setterInGlobalScope = extensionValue;
//^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
// ^^^
// [cfe] unspecified
bool t2 = a.methodInGlobalScope();
// ^^^
// [cfe] unspecified
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_METHOD_ACCESS
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
checkExtensionValue(t2);
}

Expand Down
Loading

0 comments on commit 5935b91

Please sign in to comment.