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

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

Issue 11140018: Ensure that ClassElement.lookupConstructor fails when looking up default constructor using Selector… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed String and SourceString comparison. Created 8 years, 2 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 | « lib/compiler/implementation/elements/elements.dart ('k') | tests/compiler/dart2js/resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/resolver.dart
diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart
index 7409bc630c7e7b8040e27f8555357b4fa7239f42..85549946526e163414ef5b0d23d59d3c3e48ed10 100644
--- a/lib/compiler/implementation/resolver.dart
+++ b/lib/compiler/implementation/resolver.dart
@@ -89,8 +89,17 @@ class ResolverTask extends CompilerTask {
bool isNamedConstructor(Send node) => node.receiver !== null;
- SourceString getConstructorName(Send node) {
- return node.selector.asIdentifier().source;
+ SourceString getConstructorName(Send node, SourceString className) {
kasperl 2012/10/15 07:26:38 Maybe this helper could give you the selector inst
aam-me 2012/10/15 12:07:52 Done.
+ if (!isNamedConstructor(node)) {
+ return const SourceString("");
+ } else {
+ SourceString constructorName = node.selector.asIdentifier().source;
+ if (constructorName.slowToString() != className.slowToString()) {
+ return constructorName;
+ } else {
+ return const SourceString("");
+ }
+ }
}
String constructorNameForDiagnostics(SourceString className,
@@ -117,15 +126,15 @@ class ResolverTask extends CompilerTask {
if (!initializers.isEmpty() &&
Initializers.isConstructorRedirect(initializers.head)) {
final ClassElement classElement = constructor.getEnclosingClass();
+ SourceString constructorName = getConstructorName(initializers.head, classElement.name);
kasperl 2012/10/15 07:26:38 Long line.
aam-me 2012/10/15 12:07:52 Done.
Selector selector;
- if (isNamedConstructor(initializers.head)) {
- SourceString constructorName = getConstructorName(initializers.head);
+ if (constructorName != const SourceString("")) {
selector = new Selector.callConstructor(
- constructorName,
- resolver.visitor.enclosingElement.getLibrary());
+ constructorName,
+ resolver.visitor.enclosingElement.getLibrary());
} else {
selector = new Selector.callDefaultConstructor(
- resolver.visitor.enclosingElement.getLibrary());
+ resolver.visitor.enclosingElement.getLibrary());
}
return classElement.lookupConstructor(selector);
}
@@ -745,15 +754,13 @@ class InitializerResolver {
call);
final SourceString className = lookupTarget.name;
- SourceString constructorName;
+ SourceString constructorName = resolver.getConstructorName(call, className);
Selector lookupSelector;
- if (resolver.isNamedConstructor(call)) {
- constructorName = resolver.getConstructorName(call);
+ if (constructorName != const SourceString('')) {
lookupSelector = new Selector.callConstructor(
constructorName,
visitor.enclosingElement.getLibrary());
} else {
- constructorName = const SourceString('');
lookupSelector = new Selector.callDefaultConstructor(
visitor.enclosingElement.getLibrary());
}
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | tests/compiler/dart2js/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698