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

Unified Diff: dart/lib/compiler/implementation/resolver.dart

Issue 10575033: Implement override checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 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
« no previous file with comments | « dart/lib/compiler/implementation/elements/elements.dart ('k') | dart/lib/isolate/frog/ports.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/lib/compiler/implementation/resolver.dart
diff --git a/dart/lib/compiler/implementation/resolver.dart b/dart/lib/compiler/implementation/resolver.dart
index 3ab84c7dc809e0ce33018a5d292fe93d2917124b..94faf24a05a986c73eac58ed45b7b4308deaa6cf 100644
--- a/dart/lib/compiler/implementation/resolver.dart
+++ b/dart/lib/compiler/implementation/resolver.dart
@@ -229,6 +229,50 @@ class ResolverTask extends CompilerTask {
new ClassResolverVisitor(compiler, element.getLibrary(), element);
visitor.visit(tree);
element.isResolved = true;
+
+ while (!toResolve.isEmpty()) {
+ ClassElement classElement = toResolve.removeFirst();
+ classElement.ensureResolved(compiler);
+ }
+
+ checkOverrides(element);
+ });
+ }
+
+ checkOverrides(ClassElement cls) {
+ if (cls === compiler.objectClass) return;
+ cls.forEachMember((holder, member) {
+ Element superMember = cls.lookupSuperMember(member.name);
+ if (superMember !== null) {
+ if (member.modifiers.isStatic()) {
+ compiler.cancel('Static members cannot override', element: member);
+ } else {
+ FunctionElement superFunction = superMember.asFunctionElement();
+ FunctionElement function = member.asFunctionElement();
+ if (superFunction === null || superFunction.isAccessor()) {
+ // Field or accessor in super.
+ if (function !== null && !function.isAccessor()) {
+ // But a plain method in this class.
+ compiler.cancel('Cannot override field with method',
+ element: member);
+ }
+ } else {
+ // Instance method in super.
+ if (function === null || function.isAccessor()) {
+ // But a field in this class.
karlklose 2012/06/20 13:51:31 ... or accessor ...?
ahe 2012/06/22 12:50:33 Done.
+ compiler.cancel('Cannot override method with field',
+ element: member);
+ } else {
+ // Both are plain instance methods.
+ if (superFunction.requiredParameterCount(compiler) !=
+ function.requiredParameterCount(compiler)) {
+ compiler.cancel('Bad override', element: member);
+ }
+ // TODO(ahe): Check optional parameters.
+ }
+ }
+ }
+ }
});
}
« no previous file with comments | « dart/lib/compiler/implementation/elements/elements.dart ('k') | dart/lib/isolate/frog/ports.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698