Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1621)

Unified Diff: sdk/lib/_internal/compiler/implementation/warnings.dart

Issue 12082024: Use named arguments for messages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/warnings.dart
diff --git a/sdk/lib/_internal/compiler/implementation/warnings.dart b/sdk/lib/_internal/compiler/implementation/warnings.dart
index cf7efee74cf49e9b5a3af5bb2cc7e7f9986a4c1c..343ad14d991d4941cc281ec93ccd8fff84f01fb8 100644
--- a/sdk/lib/_internal/compiler/implementation/warnings.dart
+++ b/sdk/lib/_internal/compiler/implementation/warnings.dart
@@ -8,10 +8,10 @@ class MessageKind {
final String template;
const MessageKind(this.template);
- static const GENERIC = const MessageKind('#{1}');
+ static const GENERIC = const MessageKind('#{text}');
static const NOT_ASSIGNABLE = const MessageKind(
- '#{2} is not assignable to #{1}');
+ '#{fromType} is not assignable to #{toType}');
static const VOID_EXPRESSION = const MessageKind(
'expression does not yield a value');
static const VOID_VARIABLE = const MessageKind(
@@ -19,17 +19,17 @@ class MessageKind {
static const RETURN_VALUE_IN_VOID = const MessageKind(
'cannot return value from void function');
static const RETURN_NOTHING = const MessageKind(
- 'value of type #{1} expected');
+ 'value of type #{returnType} expected');
static const MISSING_ARGUMENT = const MessageKind(
- 'missing argument of type #{1}');
+ 'missing argument of type #{argumentType}');
static const ADDITIONAL_ARGUMENT = const MessageKind(
'additional argument');
static const METHOD_NOT_FOUND = const MessageKind(
- 'no method named #{2} in class #{1}');
+ 'no method named #{methodName} in class #{className}');
static const MEMBER_NOT_STATIC = const MessageKind(
- '#{1}.#{2} is not static');
+ '#{className}.#{memberName} is not static');
static const NO_INSTANCE_AVAILABLE = const MessageKind(
- '#{1} is only available in instance methods');
+ '#{name} is only available in instance methods');
static const UNREACHABLE_CODE = const MessageKind(
'unreachable code');
@@ -39,43 +39,43 @@ class MessageKind {
'not all paths lead to a return or throw statement');
static const CANNOT_RESOLVE = const MessageKind(
- 'cannot resolve #{1}');
+ 'cannot resolve #{name}');
static const CANNOT_RESOLVE_CONSTRUCTOR = const MessageKind(
- 'cannot resolve constructor #{1}');
+ 'cannot resolve constructor #{constructorName}');
static const CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT = const MessageKind(
- 'cannot resolve constructor #{1} for implicit super call');
+ 'cannot resolve constructor #{constructorName} for implicit super call');
static const CANNOT_RESOLVE_TYPE = const MessageKind(
- 'cannot resolve type #{1}');
+ 'cannot resolve type #{typeName}');
static const DUPLICATE_DEFINITION = const MessageKind(
- 'duplicate definition of #{1}');
+ 'duplicate definition of #{name}');
static const DUPLICATE_IMPORT = const MessageKind(
- 'duplicate import of #{1}');
+ 'duplicate import of #{name}');
static const DUPLICATE_EXPORT = const MessageKind(
- 'duplicate export of #{1}');
+ 'duplicate export of #{name}');
static const NOT_A_TYPE = const MessageKind(
- '#{1} is not a type');
+ '#{node} is not a type');
static const NOT_A_PREFIX = const MessageKind(
- '#{1} is not a prefix');
+ '#{node} is not a prefix');
static const NO_SUPER_IN_OBJECT = const MessageKind(
"'Object' does not have a superclass");
static const CANNOT_FIND_CONSTRUCTOR = const MessageKind(
- 'cannot find constructor #{1}');
+ 'cannot find constructor #{constructorName}');
static const CANNOT_FIND_CONSTRUCTOR2 = const MessageKind(
- 'cannot find constructor #{1} in #{2}');
+ 'cannot find constructor #{constructorName} in #{className}');
static const CYCLIC_CLASS_HIERARCHY = const MessageKind(
- '#{1} creates a cycle in the class hierarchy');
+ '#{className} creates a cycle in the class hierarchy');
static const INVALID_RECEIVER_IN_INITIALIZER = const MessageKind(
'field initializer expected');
static const NO_SUPER_IN_STATIC = const MessageKind(
"'super' is only available in instance methods");
static const DUPLICATE_INITIALIZER = const MessageKind(
- 'field #{1} is initialized more than once');
+ 'field #{fieldName} is initialized more than once');
static const ALREADY_INITIALIZED = const MessageKind(
- '#{1} was already initialized here');
+ '#{fieldName} was already initialized here');
static const INIT_STATIC_FIELD = const MessageKind(
- 'cannot initialize static field #{1}');
+ 'cannot initialize static field #{fieldName}');
static const NOT_A_FIELD = const MessageKind(
- '#{1} is not a field');
+ '#{fieldName} is not a field');
static const CONSTRUCTOR_CALL_EXPECTED = const MessageKind(
"only call to 'this' or 'super' constructor allowed");
static const INVALID_FOR_IN = const MessageKind(
@@ -95,19 +95,17 @@ class MessageKind {
static const DUPLICATE_SUPER_INITIALIZER = const MessageKind(
'cannot have more than one super initializer');
static const INVALID_ARGUMENTS = const MessageKind(
- "arguments do not match the expected parameters of #{1}");
+ "arguments do not match the expected parameters of #{methodName}");
static const NO_MATCHING_CONSTRUCTOR = const MessageKind(
"super call arguments and constructor parameters don't match");
static const NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT = const MessageKind(
"implicit super call arguments and constructor parameters don't match");
- static const NO_CONSTRUCTOR = const MessageKind(
- '#{1} is a #{2}, not a constructor');
static const FIELD_PARAMETER_NOT_ALLOWED = const MessageKind(
'a field parameter is only allowed in generative constructors');
static const INVALID_PARAMETER = const MessageKind(
"cannot resolve parameter");
static const NOT_INSTANCE_FIELD = const MessageKind(
- '#{1} is not an instance field');
+ '#{fieldName} is not an instance field');
static const NO_CATCH_NOR_FINALLY = const MessageKind(
"expected 'catch' or 'finally'");
static const EMPTY_CATCH_DECLARATION = const MessageKind(
@@ -124,27 +122,30 @@ class MessageKind {
'cannot use re-throw outside of catch block (expression expected after '
'"throw")');
static const UNBOUND_LABEL = const MessageKind(
- 'cannot resolve label #{1}');
+ 'cannot resolve label #{labelName}');
static const NO_BREAK_TARGET = const MessageKind(
'break statement not inside switch or loop');
static const NO_CONTINUE_TARGET = const MessageKind(
'continue statement not inside loop');
static const EXISTING_LABEL = const MessageKind(
- 'original declaration of duplicate label #{1}');
+ 'original declaration of duplicate label #{labelName}');
static const DUPLICATE_LABEL = const MessageKind(
- 'duplicate declaration of label #{1}');
+ 'duplicate declaration of label #{labelName}');
static const UNUSED_LABEL = const MessageKind(
- 'unused label #{1}');
+ 'unused label #{labelName}');
static const INVALID_CONTINUE = const MessageKind(
'target of continue is not a loop or switch case');
+ static const INVALID_BREAK = const MessageKind(
+ 'target of break is not a statement');
+
static const TYPE_VARIABLE_AS_CONSTRUCTOR = const MessageKind(
'cannot use type variable as constructor');
static const DUPLICATE_TYPE_VARIABLE_NAME = const MessageKind(
- 'type variable #{1} already declared');
+ 'type variable #{typeVariableName} already declared');
static const TYPE_VARIABLE_WITHIN_STATIC_MEMBER = const MessageKind(
- 'cannot refer to type variable #{1} within a static member');
- static const INVALID_BREAK = const MessageKind(
- 'target of break is not a statement');
+ 'cannot refer to type variable #{typeVariableName} '
+ 'within a static member');
+
static const INVALID_USE_OF_SUPER = const MessageKind(
'super not allowed here');
static const INVALID_CASE_DEFAULT = const MessageKind(
@@ -171,22 +172,22 @@ class MessageKind {
'map-literal key not a string literal');
static const NO_SUCH_LIBRARY_MEMBER = const MessageKind(
- '#{1} has no member named #{2}');
+ '#{libraryName} has no member named #{memberName}');
static const CANNOT_INSTANTIATE_INTERFACE = const MessageKind(
- "cannot instantiate interface '#{1}'");
+ "cannot instantiate interface '#{interfaceName}'");
static const CANNOT_INSTANTIATE_TYPEDEF = const MessageKind(
- "cannot instantiate typedef '#{1}'");
+ "cannot instantiate typedef '#{typedefName}'");
static const CANNOT_INSTANTIATE_TYPE_VARIABLE = const MessageKind(
- "cannot instantiate type variable '#{1}'");
+ "cannot instantiate type variable '#{typeVariableName}'");
static const NO_DEFAULT_CLASS = const MessageKind(
- "no default class on enclosing interface '#{1}'");
+ "no default class on enclosing interface '#{interfaceName}'");
static const CYCLIC_TYPE_VARIABLE = const MessageKind(
- "cyclic reference to type variable #{1}");
+ "cyclic reference to type variable #{typeVariableName}");
static const CLASS_NAME_EXPECTED = const MessageKind(
"class name expected");
@@ -195,19 +196,20 @@ class MessageKind {
"interface type expected");
static const CANNOT_EXTEND = const MessageKind(
- "#{1} cannot be extended");
+ "#{type} cannot be extended");
static const CANNOT_IMPLEMENT = const MessageKind(
- "#{1} cannot be implemented");
+ "#{type} cannot be implemented");
static const DUPLICATE_EXTENDS_IMPLEMENTS = const MessageKind(
- "Error: #{1} can not be both extended and implemented.");
+ "Error: #{type} can not be both extended and implemented.");
static const DUPLICATE_IMPLEMENTS = const MessageKind(
- "Error: #{1} must not occur more than once in the implements clause.");
+ "Error: #{type} must not occur more than once "
+ "in the implements clause.");
static const ILLEGAL_SUPER_SEND = const MessageKind(
- "#{1} cannot be called on super");
+ "#{name} cannot be called on super");
static const ADDITIONAL_TYPE_ARGUMENT = const MessageKind(
"additional type argument");
@@ -218,41 +220,42 @@ class MessageKind {
// TODO(johnniwinther): Use ADDITIONAL_TYPE_ARGUMENT or MISSING_TYPE_ARGUMENT
// instead.
static const TYPE_ARGUMENT_COUNT_MISMATCH = const MessageKind(
- "incorrect number of type arguments on #{1}");
+ "incorrect number of type arguments on #{type}");
static const MISSING_ARGUMENTS_TO_ASSERT = const MessageKind(
"missing arguments to assert");
static const GETTER_MISMATCH = const MessageKind(
- "Error: setter disagrees on: #{1}.");
+ "Error: setter disagrees on: #{modifiers}.");
static const SETTER_MISMATCH = const MessageKind(
- "Error: getter disagrees on: #{1}.");
+ "Error: getter disagrees on: #{modifiers}.");
static const ILLEGAL_SETTER_FORMALS = const MessageKind(
"Error: a setter must have exactly one argument.");
static const NO_STATIC_OVERRIDE = const MessageKind(
- "Error: static member cannot override instance member '#{1}' of '#{2}'.");
+ "Error: static member cannot override instance member '#{memberName}' of "
+ "'#{className}'.");
static const NO_STATIC_OVERRIDE_CONT = const MessageKind(
"Info: this is the instance member that cannot be overridden "
"by a static member.");
static const CANNOT_OVERRIDE_FIELD_WITH_METHOD = const MessageKind(
- "Error: method cannot override field '#{1}' of '#{2}'.");
+ "Error: method cannot override field '#{memberName}' of '#{className}'.");
static const CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT = const MessageKind(
"Info: this is the field that cannot be overridden by a method.");
static const CANNOT_OVERRIDE_METHOD_WITH_FIELD = const MessageKind(
- "Error: field cannot override method '#{1}' of '#{2}'.");
+ "Error: field cannot override method '#{memberName}' of '#{className}'.");
static const CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT = const MessageKind(
"Info: this is the method that cannot be overridden by a field.");
static const BAD_ARITY_OVERRIDE = const MessageKind(
- "Error: cannot override method '#{1}' in '#{2}'; "
+ "Error: cannot override method '#{memberName}' in '#{className}'; "
"the parameters do not match.");
static const BAD_ARITY_OVERRIDE_CONT = const MessageKind(
@@ -265,33 +268,33 @@ class MessageKind {
"Error: Formal parameters are not allowed here.");
static const UNARY_OPERATOR_BAD_ARITY = const MessageKind(
- "Error: Operator #{1} must have no parameters.");
+ "Error: Operator #{operatorName} must have no parameters.");
static const MINUS_OPERATOR_BAD_ARITY = const MessageKind(
"Error: Operator - must have 0 or 1 parameters.");
static const BINARY_OPERATOR_BAD_ARITY = const MessageKind(
- "Error: Operator #{1} must have exactly 1 parameter.");
+ "Error: Operator #{operatorName} must have exactly 1 parameter.");
static const TERNARY_OPERATOR_BAD_ARITY = const MessageKind(
- "Error: Operator #{1} must have exactly 2 parameters.");
+ "Error: Operator #{operatorName} must have exactly 2 parameters.");
static const OPERATOR_OPTIONAL_PARAMETERS = const MessageKind(
- "Error: Operator #{1} cannot have optional parameters.");
+ "Error: Operator #{operatorName} cannot have optional parameters.");
static const OPERATOR_NAMED_PARAMETERS = const MessageKind(
- "Error: Operator #{1} cannot have named parameters.");
+ "Error: Operator #{operatorName} cannot have named parameters.");
// TODO(ahe): This message is hard to localize. This is acceptable,
// as it will be removed when we ship Dart version 1.0.
static const DEPRECATED_FEATURE_WARNING = const MessageKind(
- "Warning: deprecated language feature, #{1}, "
+ "Warning: deprecated language feature, #{featureName}, "
"will be removed in a future Dart milestone.");
// TODO(ahe): This message is hard to localize. This is acceptable,
// as it will be removed when we ship Dart version 1.0.
static const DEPRECATED_FEATURE_ERROR = const MessageKind(
- "Error: #{1} are not legal "
+ "Error: #{featureName} are not legal "
"due to option --reject-deprecated-language-features.");
static const CONSTRUCTOR_WITH_RETURN_TYPE = const MessageKind(
@@ -301,10 +304,10 @@ class MessageKind {
"Error: cannot have final modifier on method.");
static const ILLEGAL_CONSTRUCTOR_MODIFIERS = const MessageKind(
- "Error: illegal constructor modifiers: #{1}.");
+ "Error: illegal constructor modifiers: #{modifiers}.");
static const ILLEGAL_MIXIN_APPLICATION_MODIFIERS = const MessageKind(
- "Error: illegal mixin application modifiers: #{1}.");
+ "Error: illegal mixin application modifiers: #{modifiers}.");
static const ILLEGAL_MIXIN_SUPERCLASS = const MessageKind(
"Error: class used as mixin must have Object as superclass.");
@@ -313,10 +316,11 @@ class MessageKind {
"Error: class used as mixin cannot have non-factory constructor.");
static const ILLEGAL_MIXIN_CYCLE = const MessageKind(
- "Error: class used as mixin introduces mixin cycle: #{1} <-> #{2}.");
+ "Error: class used as mixin introduces mixin cycle: "
+ "#{mixinName1} <-> #{mixinName2}.");
static const ILLEGAL_MIXIN_WITH_SUPER = const MessageKind(
- "Error: cannot use class #{1} as a mixin because it uses super.");
+ "Error: cannot use class #{className} as a mixin because it uses super.");
static const ILLEGAL_MIXIN_SUPER_USE = const MessageKind(
"Use of super in class used as mixin.");
@@ -337,7 +341,7 @@ class MessageKind {
'Error: part header must come before top-level definitions.');
static const LIBRARY_NAME_MISMATCH = const MessageKind(
- 'Warning: expected part of library name "#{1}".');
+ 'Warning: expected part of library name "#{libraryName}".');
static const MISSING_PART_OF_TAG = const MessageKind(
'Note: This file has no part-of tag, but it is being used as a part.');
@@ -349,31 +353,34 @@ class MessageKind {
'Error: directive not allowed here.');
static const DUPLICATED_LIBRARY_NAME = const MessageKind(
- 'Warning: duplicated library name "#{1}".');
+ 'Warning: duplicated library name "#{libraryName}".');
static const INVALID_SOURCE_FILE_LOCATION = const MessageKind('''
-Invalid offset (#{1}) in source map.
-File: #{2}
-Length: #{3}''');
+Invalid offset (#{offset}) in source map.
+File: #{fileName}
+Length: #{length}''');
static const PATCH_RETURN_TYPE_MISMATCH = const MessageKind(
- "Patch return type '#{3}' doesn't match '#{2}' on origin method '#{1}'.");
+ "Patch return type '#{patchReturnType}' doesn't match "
+ "'#{originReturnType}' on origin method '#{methodName}'.");
static const PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH = const MessageKind(
- "Required parameter count of patch method (#{3}) doesn't match parameter "
- "count on origin method '#{1}' (#{2}).");
+ "Required parameter count of patch method (#{patchParameterCount}) "
+ "doesn't match parameter count on origin method '#{methodName}' "
+ "(#{originParameterCount}).");
static const PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH = const MessageKind(
- "Optional parameter count of patch method (#{3}) doesn't match parameter "
- "count on origin method '#{1}' (#{2}).");
+ "Optional parameter count of patch method (#{patchParameterCount}) "
+ "doesn't match parameter count on origin method '#{methodName}' "
+ "(#{originParameterCount}).");
static const PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH = const MessageKind(
- "Optional parameters of origin and patch method '#{1}' must "
+ "Optional parameters of origin and patch method '#{methodName}' must "
"both be either named or positional.");
static const PATCH_PARAMETER_MISMATCH = const MessageKind(
- "Patch method parameter '#{3}' doesn't match '#{2}' on origin method "
- "#{1}.");
+ "Patch method parameter '#{patchParameter}' doesn't match "
+ "'#{originParameter}' on origin method #{methodName}.");
static const EXTERNAL_WITHOUT_IMPLEMENTATION = const MessageKind(
"External method without an implementation.");
@@ -382,13 +389,11 @@ Length: #{3}''');
"Top-level variable cannot be declared static.");
static const WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT = const MessageKind(
- "Wrong number of arguments to assert. Should be 1, but given #{1}.");
+ "Wrong number of arguments to assert. Should be 1, but given "
+ "#{argumentCount}.");
static const ASSERT_IS_GIVEN_NAMED_ARGUMENTS = const MessageKind(
- "assert takes no named arguments, but given #{1}.");
-
- static const MALFORMED_TYPE_REFERENCE = const MessageKind(
- "Malformed type reference encountered in #{1}.");
+ "assert takes no named arguments, but given #{argumentCount}.");
static const FACTORY_REDIRECTION_IN_NON_FACTORY = const MessageKind(
"Error: Factory redirection only allowed in factories.");
@@ -413,7 +418,7 @@ Please include the following information:
* the name and version of your operating system,
-* the Dart SDK build number (#{1}), and
+* the Dart SDK build number (#{buildId}), and
* the entire message you see here (including the full stack trace
below as well as the source location above).
@@ -421,34 +426,43 @@ Please include the following information:
toString() => template;
- Message message([List arguments = const []]) {
+ Message message([Map arguments = const {}]) {
return new Message(this, arguments);
}
- CompilationError error([List arguments = const []]) {
+ CompilationError error([Map arguments = const {}]) {
return new CompilationError(this, arguments);
}
}
class Message {
final kind;
- final List arguments;
+ final Map arguments;
String message;
- Message(this.kind, this.arguments);
+ Message(this.kind, this.arguments) {
+ assert(() { computeMessage(); return true; });
+ }
- String toString() {
+ String computeMessage() {
if (message == null) {
message = kind.template;
- int position = 1;
- for (var argument in arguments) {
- String string = slowToString(argument);
- message = message.replaceAll('#{${position++}}', string);
- }
+ arguments.forEach((key, value) {
+ String string = slowToString(value);
+ message = message.replaceAll('#{${key}}', string);
+ });
+ assert(invariant(
+ CURRENT_ELEMENT_SPANNABLE,
+ !message.contains(new RegExp(r"#\{.+\}")),
+ message: 'Missing arguments in error message: "$message"'));
}
return message;
}
+ String toString() {
+ return computeMessage();
+ }
+
bool operator==(other) {
if (other is !Message) return false;
return (kind == other.kind) && (toString() == other.toString());
@@ -465,32 +479,32 @@ class Message {
class Diagnostic {
final Message message;
- Diagnostic(MessageKind kind, List arguments)
- : message = new Message(kind, arguments);
+ Diagnostic(MessageKind kind, [Map arguments = const {}])
+ : message = new Message(kind, arguments);
String toString() => message.toString();
}
class TypeWarning extends Diagnostic {
- TypeWarning(MessageKind kind, List arguments)
+ TypeWarning(MessageKind kind, [Map arguments = const {}])
: super(kind, arguments);
}
class ResolutionError extends Diagnostic {
- ResolutionError(MessageKind kind, List arguments)
- : super(kind, arguments);
+ ResolutionError(MessageKind kind, [Map arguments = const {}])
+ : super(kind, arguments);
}
class ResolutionWarning extends Diagnostic {
- ResolutionWarning(MessageKind kind, List arguments)
+ ResolutionWarning(MessageKind kind, [Map arguments = const {}])
: super(kind, arguments);
}
class CompileTimeConstantError extends Diagnostic {
- CompileTimeConstantError(MessageKind kind, List arguments)
+ CompileTimeConstantError(MessageKind kind, [Map arguments = const {}])
: super(kind, arguments);
}
class CompilationError extends Diagnostic {
- CompilationError(MessageKind kind, List arguments)
+ CompilationError(MessageKind kind, [Map arguments = const {}])
: super(kind, arguments);
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/util/util.dart ('k') | tests/compiler/dart2js/erroneous_element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698