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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java

Issue 9250017: Allow classes shadowed by type variables to be referenced in static context (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: oops, left bad test in. Created 8 years, 11 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 | compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java b/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
index 9df0997de001d7e6a765a805d5f8ad42f6484c67..df8618d79df308c8e5c3553fa5eb0ceaa9d73f6e 100644
--- a/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
+++ b/compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java
@@ -1,9 +1,8 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.google.dart.compiler.resolver;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.dart.compiler.DartCompilationError;
import com.google.dart.compiler.DartCompilerContext;
@@ -25,6 +24,7 @@ import com.google.dart.compiler.type.TypeVariable;
import java.util.Arrays;
import java.util.List;
+
/**
* Resolution context for resolution of Dart programs. The initial context is
* derived from the library scope, which is then extended with class scope,
@@ -190,9 +190,30 @@ public class ResolutionContext implements ResolutionErrorListener {
TypeVariableElement typeVariableElement = (TypeVariableElement) element;
if (!isFactory && isStatic &&
typeVariableElement.getDeclaringElement().getKind().equals(ElementKind.CLASS)) {
- onError(identifier, ResolverErrorCode.TYPE_VARIABLE_IN_STATIC_CONTEXT,
- identifier);
- return typeProvider.getDynamicType();
+
+ // Check that type variable is not shadowing any element in enclosing context.
+ Scope libraryScope = scope.getLibrary().getScope();
+ String name = element.getName();
+ Element existingElement = libraryScope.findElement(scope.getLibrary(), name);
+
+ switch(ElementKind.of(existingElement)) {
+ case CLASS:
+ case FUNCTION_TYPE_ALIAS:
+ return instantiateParameterizedType((ClassElement)existingElement,
+ diagnosticNode,
+ typeArguments,
+ isStatic,
+ isFactory,
+ errorCode);
+ case NONE:
+ onError(identifier, ResolverErrorCode.TYPE_VARIABLE_IN_STATIC_CONTEXT,
+ identifier);
+ return typeProvider.getDynamicType();
+
+ default:
+ onError(identifier, TypeErrorCode.NOT_A_TYPE, identifier, elementKind);
+ return typeProvider.getDynamicType();
+ }
}
return makeTypeVariable(typeVariableElement, typeArguments);
}
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/common/ErrorExpectation.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698