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

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

Issue 140803002: Perform override and inheritance checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 454b0d1bb63c42da598e0eb69768c4f464d251c9..8c85d703598bb7771de85323d5a56fd82c714a8f 100644
--- a/sdk/lib/_internal/compiler/implementation/warnings.dart
+++ b/sdk/lib/_internal/compiler/implementation/warnings.dart
@@ -865,10 +865,77 @@ main() => new C();
"Info: This is the instance member that cannot be overridden "
"by a static member.");
+ static const MessageKind INSTANCE_STATIC_SAME_NAME = const MessageKind(
+ "Warning: Instance member '#{memberName}' and static member of "
+ "superclass '#{className}' have the same name.");
+
+ static const MessageKind INSTANCE_STATIC_SAME_NAME_CONT = const MessageKind(
+ "Info: This is the static member with the same name.");
+
+ static const MessageKind INVALID_OVERRIDE_METHOD = const MessageKind(
+ "Warning: The type '#{declaredType}' of method '#{name}' declared in "
+ "'#{class}' is not a subtype of the overridden method type "
+ "'#{inheritedType}' inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDDEN_METHOD = const MessageKind(
+ "Info: This is the overridden method '#{name}' declared in class "
+ "'#{class}'.");
+
+ static const MessageKind INVALID_OVERRIDE_GETTER = const MessageKind(
+ "Warning: The type '#{declaredType}' of getter '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden getter inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDDEN_GETTER = const MessageKind(
+ "Info: This is the overridden getter '#{name}' declared in class "
+ "'#{class}'.");
+
+ static const MessageKind INVALID_OVERRIDE_GETTER_WITH_FIELD =
+ const MessageKind(
+ "Warning: The type '#{declaredType}' of field '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden getter inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDE_FIELD_WITH_GETTER =
+ const MessageKind(
+ "Warning: The type '#{declaredType}' of getter '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden field inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDE_SETTER = const MessageKind(
+ "Warning: The type '#{declaredType}' of setter '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden setter inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDDEN_SETTER = const MessageKind(
+ "Info: This is the overridden setter '#{name}' declared in class "
+ "'#{class}'.");
+
+ static const MessageKind INVALID_OVERRIDE_SETTER_WITH_FIELD =
+ const MessageKind(
+ "Warning: The type '#{declaredType}' of field '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden setter inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDE_FIELD_WITH_SETTER =
+ const MessageKind(
+ "Warning: The type '#{declaredType}' of setter '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden field inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDE_FIELD = const MessageKind(
+ "Warning: The type '#{declaredType}' of field '#{name}' declared in "
+ "'#{class}' is not assignable to the type '#{inheritedType}' of the "
+ "overridden field inherited from '#{inheritedClass}'.");
+
+ static const MessageKind INVALID_OVERRIDDEN_FIELD = const MessageKind(
+ "Info: This is the overridden field '#{name}' declared in class "
+ "'#{class}'.");
+
static const MessageKind CANNOT_OVERRIDE_FIELD_WITH_METHOD =
const MessageKind(
- "Error: Method cannot override field '#{memberName}' of "
- "'#{className}'.");
+ "Error: Method '#{name}' in '#{class}' can't override field from "
+ "'#{inheritedClass}'.");
static const MessageKind CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT =
const MessageKind(
@@ -876,19 +943,30 @@ main() => new C();
static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_FIELD =
const MessageKind(
- "Error: Field cannot override method '#{memberName}' of "
- "'#{className}'.");
+ "Error: Field '#{name}' in '#{class}' can't override method from "
+ "'#{inheritedClass}'.");
static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT =
const MessageKind(
"Info: This is the method that cannot be overridden by a field.");
- static const MessageKind BAD_ARITY_OVERRIDE = const MessageKind(
- "Error: Cannot override method '#{memberName}' in '#{className}'; "
- "the parameters do not match.");
+ static const MessageKind CANNOT_OVERRIDE_GETTER_WITH_METHOD =
+ const MessageKind(
+ "Error: Method '#{name}' in '#{class}' can't override getter from "
+ "'#{inheritedClass}'.");
- static const MessageKind BAD_ARITY_OVERRIDE_CONT = const MessageKind(
- "Info: This is the method whose parameters do not match.");
+ static const MessageKind CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT =
+ const MessageKind(
+ "Info: This is the getter that cannot be overridden by a method.");
+
+ static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_GETTER =
+ const MessageKind(
+ "Error: Getter '#{name}' in '#{class}' can't override method from "
+ "'#{inheritedClass}'.");
+
+ static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT =
+ const MessageKind(
+ "Info: This is the method that cannot be overridden by a getter.");
static const MessageKind MISSING_FORMALS = const MessageKind(
"Error: Formal parameters are missing.");
@@ -1373,41 +1451,265 @@ main() {}
howToFix: "Consider deleting it.",
examples: const ["deadCode() {} main() {}"]);
+ static const MessageKind ABSTRACT_METHOD = const MessageKind(
+ "Warning: The method '#{name}' has no implementation in "
+ "class '#{class}'.",
+ howToFix: "Try adding a body to '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+class Class {
+ method();
+}
+main() => new Class();
+"""]);
+
+ static const MessageKind ABSTRACT_GETTER = const MessageKind(
+ "Warning: The getter '#{name}' has no implementation in "
+ "class '#{class}'.",
+ howToFix: "Try adding a body to '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+class Class {
+ get getter;
+}
+main() => new Class();
+"""]);
+
+ static const MessageKind ABSTRACT_SETTER = const MessageKind(
+ "Warning: The setter '#{name}' has no implementation in "
+ "class '#{class}'.",
+ howToFix: "Try adding a body to '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+class Class {
+ set setter(_);
+}
+main() => new Class();
+"""]);
+
+ static const MessageKind INHERIT_GETTER_AND_METHOD = const MessageKind(
+ "Warning: The class '#{class}' can't inherit both getters and methods "
+ "by the named '#{name}'.",
+ howToFix: DONT_KNOW_HOW_TO_FIX,
+ examples: const ["""
+class A {
+ get member => null;
+}
+class B {
+ member() {}
+}
+class Class implements A, B {
+}
+main() => new Class();
+"""]);
+
+ static const MessageKind INHERITED_METHOD = const MessageKind(
+ "Info: The inherited method '#{name}' is declared here in class "
+ "'#{class}'.");
+
+ static const MessageKind INHERITED_EXPLICIT_GETTER = const MessageKind(
+ "Info: The inherited getter '#{name}' is declared here in class "
+ "'#{class}'.");
+
+ static const MessageKind INHERITED_IMPLICIT_GETTER = const MessageKind(
+ "Info: The inherited getter '#{name}' is implicitly declared by this "
+ "field in class '#{class}'.");
+
+ static const MessageKind UNIMPLEMENTED_METHOD_ONE = const MessageKind(
+ "Warning: '#{class}' doesn't implement '#{method}' "
+ "declared in '#{declarer}'.",
+ howToFix: "Try adding an implementation of '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+abstract class I {
+ m();
+}
+
karlklose 2014/01/28 12:27:45 I would prefer shortening the examples - at least
Johnni Winther 2014/01/31 12:29:30 Done.
+class C implements I {}
+
+main() {
+ new C();
+}
+""", """
+abstract class I {
+ m();
+}
+
+class C extends I {}
+
+main() {
+ new C();
+}
+"""]);
+
static const MessageKind UNIMPLEMENTED_METHOD = const MessageKind(
- "Warning: '#{class_name}' doesn't implement '#{member_name}'.",
- howToFix: "Try adding an implementation of '#{member_name}'.",
+ "Warning: '#{class}' doesn't implement '#{method}'.",
+ howToFix: "Try adding an implementation of '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
examples: const ["""
abstract class I {
m();
}
+abstract class J {
+ m();
+}
+
+class C implements I, J {}
+
+main() {
+ new C();
+}
+""", """
+abstract class I {
+ m();
+}
+
+abstract class J {
+ m();
+}
+
+class C extends I implements J {}
+
+main() {
+ new C();
+}
+"""]);
+
+ static const MessageKind UNIMPLEMENTED_METHOD_CONT = const MessageKind(
+ "Info: The method '#{name}' is declared here in class '#{class}'.");
+
+ static const MessageKind UNIMPLEMENTED_SETTER_ONE = const MessageKind(
+ "Warning: '#{class}' doesn't implement the setter '#{name}' "
+ "declared in '#{declarer}'.",
+ howToFix: "Try adding an implementation of '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+abstract class I {
+ set m(_);
+}
+
class C implements I {}
class D implements I {
- m() {}
+ set m(_) {}
+}
+
+main() {
+ new D().m = 0;
+ new C();
+}
+"""]);
+
+ static const MessageKind UNIMPLEMENTED_SETTER = const MessageKind(
+ "Warning: '#{class}' doesn't implement the setter '#{name}'.",
+ howToFix: "Try adding an implementation of '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+abstract class I {
+ set m(_);
+}
+
+abstract class J {
+ set m(_);
}
+class C implements I, J {}
+
main() {
- new D().m();
new C();
}
""", """
abstract class I {
- m();
+ set m(_);
+}
+
+abstract class J {
+ set m(_);
+}
+
+class C extends I implements J {}
+
+main() {
+ new C();
+}
+"""]);
+
+ static const MessageKind UNIMPLEMENTED_EXPLICIT_SETTER = const MessageKind(
+ "Info: The setter '#{name}' is declared here in class '#{class}'.");
+
+ static const MessageKind UNIMPLEMENTED_IMPLICIT_SETTER = const MessageKind(
+ "Info: The setter '#{name}' is implicitly declared by this field "
+ "in class '#{class}'.");
+
+ static const MessageKind UNIMPLEMENTED_GETTER_ONE = const MessageKind(
+ "Warning: '#{class}' doesn't implement the getter '#{name}' "
+ "declared in '#{declarer}'.",
+ howToFix: "Try adding an implementation of '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+abstract class I {
+ get m;
+}
+
+class C implements I {}
+
+main() {
+ new C();
+}
+""", """
+abstract class I {
+ get m;
}
class C extends I {}
-class D extends I {
- m() {}
+main() {
+ new C();
+}
+"""]);
+
+ static const MessageKind UNIMPLEMENTED_GETTER = const MessageKind(
+ "Warning: '#{class}' doesn't implement the getter '#{name}'.",
+ howToFix: "Try adding an implementation of '#{name}' or declaring "
+ "'#{class}' to be 'abstract'.",
+ examples: const ["""
+abstract class I {
+ get m;
+}
+
+abstract class J {
+ get m;
}
+class C implements I, J {}
+
+main() {
+ new C();
+}
+""", """
+abstract class I {
+ get m;
+}
+
+abstract class J {
+ get m;
+}
+
+class C extends I implements J {}
+
main() {
- new D().m();
new C();
}
"""]);
+ static const MessageKind UNIMPLEMENTED_EXPLICIT_GETTER = const MessageKind(
+ "Info: The getter '#{name}' is declared here in class '#{class}'.");
+
+ static const MessageKind UNIMPLEMENTED_IMPLICIT_GETTER = const MessageKind(
+ "Info: The getter '#{name}' is implicitly declared by this field "
+ "in class '#{class}'.");
+
static const MessageKind COMPILER_CRASHED = const MessageKind(
"Error: The compiler crashed when compiling this element.");
@@ -1608,7 +1910,8 @@ class Message {
});
assert(invariant(
CURRENT_ELEMENT_SPANNABLE,
- !message.contains(new RegExp(r'#\{.+\}')),
+ kind == MessageKind.GENERIC ||
+ !message.contains(new RegExp(r'#\{.+\}')),
message: 'Missing arguments in error message: "$message"'));
if (!terse && kind.hasHowToFix) {
String howToFix = kind.howToFix;

Powered by Google App Engine
This is Rietveld 408576698