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

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

Issue 9980004: Look up the correct constructor for default classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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: lib/compiler/implementation/resolver.dart
diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart
index 38909e31f51a14e1d32e72ff97a4216f3cc95f6b..60f00948603529dbfb47de28653528f07d7dbd4f 100644
--- a/lib/compiler/implementation/resolver.dart
+++ b/lib/compiler/implementation/resolver.dart
@@ -167,24 +167,25 @@ class ResolverTask extends CompilerTask {
// [intrface] is an interface, let's say "MyInterface".
// [defaultClass] is a class, let's say "MyClass".
- // First look up the constructor named "MyInterface.name".
- constructor.defaultImplementation =
- defaultClass.lookupConstructor(constructor.name);
+ // If the default class implements the interface then we must use the
+ // default class' name. Otherwise we look for a factory with the name
+ // of the interface.
+ SourceString name;
+ if (defaultClass.implementsInterface(intrface)) {
+ name = new SourceString(constructor.name.slowToString().replaceFirst(
ahe 2012/04/10 14:30:38 Please add "TODO(ahe): Don't use string replacemen
floitsch 2012/04/11 11:40:56 Done.
+ intrface.name.slowToString(),
+ defaultClass.name.slowToString()));
+ } else {
+ name = constructor.name;
+ }
+ constructor.defaultImplementation = defaultClass.lookupConstructor(name);
- // If that fails, try looking up "MyClass.name".
if (constructor.defaultImplementation === null) {
- SourceString name =
- new SourceString(constructor.name.slowToString().replaceFirst(
- intrface.name.slowToString(),
- defaultClass.name.slowToString()));
- constructor.defaultImplementation = defaultClass.lookupConstructor(name);
-
- if (constructor.defaultImplementation === null) {
- // We failed find a constrcutor named either
- // "MyInterface.name" or "MyClass.name".
- error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR2,
- [constructor.name, name]);
- }
+ // We failed to find a constructor named either
+ // "MyInterface.name" or "MyClass.name".
+ error(node,
+ MessageKind.CANNOT_FIND_CONSTRUCTOR2,
+ [name, defaultClass.name]);
}
}

Powered by Google App Engine
This is Rietveld 408576698