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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 9014029: Fix dartc bounds checking for invoking interface constructors/factory methods (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added missing test file, renamed to remove 'Negative' from name Created 8 years, 12 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: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
index 10a9cf02941ca7f327d1d87301d1687cd7db4857..4b491d15756f1d97bedad8e20192abca4df97b17 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -1028,9 +1028,31 @@ public class TypeAnalyzer implements DartCompilationPhase {
public Type visitNewExpression(DartNewExpression node) {
ConstructorElement constructorElement = node.getSymbol();
node.setReferencedElement(constructorElement);
+
DartTypeNode typeNode = Types.constructorTypeNode(node);
+ Type type = null;
+
+ // When using a constructor defined in an interface, the bounds can be tighter
+ // in the default class than defined in the interface.
scheglov 2012/01/04 18:01:15 I don't see in tests "tighter" case, only case whe
zundel 2012/01/04 18:18:19 The spec doesn't actually state tighter bounds, bu
+ if (TypeKind.of(typeNode.getType()).equals(TypeKind.INTERFACE)
+ && ((InterfaceType)typeNode.getType()).getElement().isInterface()) {
+ InterfaceType itype = (InterfaceType)typeNode.getType();
+ ClassElement interfaceElement = itype.getElement();
+ InterfaceType defaultClassType = interfaceElement.getDefaultClass();
+ if (defaultClassType != null && defaultClassType.getElement() != null) {
+ validateBounds(typeNode.getTypeArguments(),
+ itype.getArguments(),
+ defaultClassType.getElement().getTypeParameters(),
+ false);
+ type = itype;
+ }
+ }
+ if (type == null) {
+ type = validateTypeNode(typeNode, false);
+ }
+
DartNode typeName = typeNode.getIdentifier();
- Type type = validateTypeNode(typeNode, false);
+
if (constructorElement == null) {
visit(node.getArgs());
} else {

Powered by Google App Engine
This is Rietveld 408576698