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

Unified Diff: pkg/compiler/lib/src/resolution/constructors.dart

Issue 1360153005: Normalize constructor lookup. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 | « no previous file | tests/language/private_super_constructor_lib.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/resolution/constructors.dart
diff --git a/pkg/compiler/lib/src/resolution/constructors.dart b/pkg/compiler/lib/src/resolution/constructors.dart
index 8528ca02f2c61b79217c5b089fa2d6f74407669b..36884f2ccfece2b1feefcf7cb2b46da9dfcba920 100644
--- a/pkg/compiler/lib/src/resolution/constructors.dart
+++ b/pkg/compiler/lib/src/resolution/constructors.dart
@@ -168,8 +168,8 @@ class InitializerResolver {
ClassElement lookupTarget = targetType.element;
Selector constructorSelector =
visitor.getRedirectingThisOrSuperConstructorSelector(call);
- FunctionElement calledConstructor =
- lookupTarget.lookupConstructor(constructorSelector.name);
+ ConstructorElement calledConstructor = findConstructor(
+ constructor.library, lookupTarget, constructorSelector.name);
final bool isImplicitSuperCall = false;
final String className = lookupTarget.name;
@@ -215,7 +215,9 @@ class InitializerResolver {
getSuperOrThisLookupTarget(functionNode, isSuperCall: true);
ClassElement lookupTarget = targetType.element;
Selector constructorSelector = new Selector.callDefaultConstructor();
- Element calledConstructor = lookupTarget.lookupConstructor(
+ ConstructorElement calledConstructor = findConstructor(
+ constructor.library,
+ lookupTarget,
constructorSelector.name);
final String className = lookupTarget.name;
@@ -464,12 +466,8 @@ class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> {
String constructorName) {
ClassElement cls = type.element;
cls.ensureResolved(compiler);
- ConstructorElement constructor = cls.lookupConstructor(constructorName);
- // TODO(johnniwinther): Use [Name] for lookup.
- if (Name.isPrivateName(constructorName) &&
- resolver.enclosingElement.library != cls.library) {
- constructor = null;
- }
+ ConstructorElement constructor = findConstructor(
+ resolver.enclosingElement.library, cls, constructorName);
if (constructor == null) {
String fullConstructorName =
Elements.constructorNameForDiagnostics(cls.name, constructorName);
@@ -728,3 +726,23 @@ class ConstructorResult {
return sb.toString();
}
}
+
+/// Lookup the [constructorName] constructor in [cls] and normalize the result
+/// with respect to privacy and patching.
+ConstructorElement findConstructor(
+ LibraryElement currentLibrary,
+ ClassElement cls,
+ String constructorName) {
+ if (Name.isPrivateName(constructorName) &&
+ currentLibrary.library != cls.library) {
+ // TODO(johnniwinther): Report a special error on unaccessible private
+ // constructors.
+ return null;
+ }
+ // TODO(johnniwinther): Use [Name] for lookup.
+ ConstructorElement constructor = cls.lookupConstructor(constructorName);
+ if (constructor != null) {
+ constructor = constructor.declaration;
+ }
+ return constructor;
+}
« no previous file with comments | « no previous file | tests/language/private_super_constructor_lib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698