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

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

Issue 10910098: Re-apply with a few fixes http://codereview.chromium.org/10913081/: Fix resolution of type paramete… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
Index: lib/compiler/implementation/resolver.dart
===================================================================
--- lib/compiler/implementation/resolver.dart (revision 11962)
+++ lib/compiler/implementation/resolver.dart (working copy)
@@ -452,8 +452,8 @@
annotation.resolutionState = STATE_STARTED;
Node node = annotation.parseNode(compiler);
- ResolverVisitor visitor =
- new ResolverVisitor(compiler, annotation.annotatedElement);
+ ResolverVisitor visitor = new ResolverVisitor(
+ compiler, annotation.annotatedElement.enclosingElement);
node.accept(visitor);
annotation.value = compiler.constantHandler.compileNodeWithDefinitions(
node, visitor.mapping);
@@ -971,10 +971,9 @@
: null,
this.statementScope = new StatementScope(),
typeResolver = new TypeResolver(compiler),
- scope = element.buildEnclosingScope(),
+ scope = element.buildScope(),
inCheckContext = compiler.enableTypeAssertions,
- super(compiler) {
- }
+ super(compiler);
Enqueuer get world => compiler.enqueuer.resolution;
@@ -1082,7 +1081,10 @@
}
void setupFunction(FunctionExpression node, FunctionElement function) {
- scope = new MethodScope(scope, function);
+ // If [function] is the [enclosingElement], the [scope] has
+ // already been set in the constructor of [ResolverVisitor].
+ if (function != enclosingElement) scope = new MethodScope(scope, function);
+
// Put the parameters in scope.
FunctionSignature functionParameters =
function.computeSignature(compiler);
@@ -2581,6 +2583,18 @@
abstract Element lookup(SourceString name);
}
+class VariableScope extends Scope {
+ VariableScope(parent, element) : super(parent, element);
+
+ Element add(Element newElement) {
+ throw "Cannot add element to VariableScope";
+ }
+
+ Element lookup(SourceString name) => parent.lookup(name);
+
+ String toString() => '$element > $parent';
+}
+
/**
* [TypeDeclarationScope] defines the outer scope of a type declaration in
* which the declared type variables and the entities in the enclosing scope are
@@ -2600,13 +2614,6 @@
throw "Cannot add element to TypeDeclarationScope";
}
- /**
- * Looks up [name] within the type variables declared in [element].
- */
- Element lookupTypeVariable(SourceString name) {
- return null;
- }
-
Element lookup(SourceString name) {
Link<DartType> typeVariableLink = element.typeVariables;
while (!typeVariableLink.isEmpty()) {
@@ -2662,6 +2669,8 @@
* scope and inherited members are available, in the given order.
*/
class ClassScope extends TypeDeclarationScope {
+ bool inStaticContext = false;
+
ClassScope(Scope parentScope, ClassElement element)
: super(parentScope, element);
@@ -2669,7 +2678,14 @@
ClassElement cls = element;
Element result = cls.lookupLocalMember(name);
if (result !== null) return result;
- result = super.lookup(name);
+ if (!inStaticContext) {
+ // If not in a static context, we can lookup in the
+ // TypeDeclaration scope, which contains the type variables of
+ // the class.
+ result = super.lookup(name);
+ } else {
+ result = parent.lookup(name);
+ }
if (result != null) return result;
return cls.lookupSuperMember(name);
}

Powered by Google App Engine
This is Rietveld 408576698