Index: compiler/java/com/google/dart/compiler/resolver/Resolver.java |
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java |
index 0e2c4e1fb36cff978140216b00aff76b6fe09985..2d8bd313567a2b49cf78b31bdd7e8dfbfaf3e6b0 100644 |
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java |
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java |
@@ -60,11 +60,9 @@ import com.google.dart.compiler.ast.DartVariable; |
import com.google.dart.compiler.ast.DartVariableStatement; |
import com.google.dart.compiler.ast.DartWhileStatement; |
import com.google.dart.compiler.ast.Modifiers; |
-import com.google.dart.compiler.type.FunctionType; |
import com.google.dart.compiler.type.InterfaceType; |
import com.google.dart.compiler.type.InterfaceType.Member; |
import com.google.dart.compiler.type.Type; |
-import com.google.dart.compiler.type.TypeVariable; |
import com.google.dart.compiler.util.StringUtils; |
import java.util.ArrayList; |
@@ -246,8 +244,34 @@ public class Resolver { |
} |
// Check that interface constructors have corresponding methods in default class. |
- if (cls.getDefaultClass() != null) { |
+ |
+ |
+ if (classElement.getDefaultClass() != null) { |
+ ClassElement defaultClass = classElement.getDefaultClass().getElement(); |
+ if (defaultClass.isInterface()) { |
+ onError(cls.getDefaultClass(), ResolverErrorCode.DEFAULT_MUST_SPECIFY_CLASS); |
+ } |
checkInteraceConstructors(classElement); |
+ |
+ List<? extends Type> cParams = classElement.getTypeParameters(); |
+ List<? extends Type> dParams = defaultClass.getTypeParameters(); |
+ if (cParams.size() != dParams.size()) { |
+ onError(cls.getDefaultClass(), |
+ ResolverErrorCode.DEFAULT_CLASS_MUST_HAVE_SAME_TYPE_PARAMS); |
+ } |
+ Iterator<? extends Type> cIter = cParams.iterator(); |
+ Iterator<? extends Type> dIter = dParams.iterator(); |
+ |
+ while (cIter.hasNext() && dIter.hasNext()) { |
+ Type classTypeVar = cIter.next(); |
+ Type defaultTypeVar = dIter.next(); |
+ String cName = classTypeVar.getElement().getName(); |
+ String dName = defaultTypeVar.getElement().getName(); |
+ if (!cName.equals(dName)) { |
+ onError(cls.getDefaultClass(), ResolverErrorCode.TYPE_PARAMETER_DOES_NOT_MATCH, |
+ cName, dName); |
+ } |
+ } |
} |
context = previousContext; |
@@ -261,6 +285,7 @@ public class Resolver { |
private void checkInteraceConstructors(ClassElement interfaceElement) { |
String interfaceClassName = interfaceElement.getName(); |
String defaultClassName = interfaceElement.getDefaultClass().getElement().getName(); |
+ |
for (ConstructorElement interfaceConstructor : interfaceElement.getConstructors()) { |
ConstructorElement defaultConstructor = |
resolveInterfaceConstructorInDefaultClass( |
@@ -276,7 +301,7 @@ public class Resolver { |
if (numReqInterface != numReqDefault) { |
onError( |
interfaceConstructor.getNode(), |
- ResolverErrorCode.FACTORY_CONSTRUCTOR_NUMBER_OF_REQUIRED_PARAMETERS, |
+ ResolverErrorCode.DEFAULT_CONSTRUCTOR_NUMBER_OF_REQUIRED_PARAMETERS, |
Elements.getRawMethodName(interfaceConstructor), |
interfaceClassName, |
numReqInterface, |
@@ -292,7 +317,7 @@ public class Resolver { |
if (!interfaceNames.equals(defaultNames)) { |
onError( |
interfaceConstructor.getNode(), |
- ResolverErrorCode.FACTORY_CONSTRUCTOR_NAMED_PARAMETERS, |
+ ResolverErrorCode.DEFAULT_CONSTRUCTOR_NAMED_PARAMETERS, |
Elements.getRawMethodName(interfaceConstructor), |
interfaceClassName, |
interfaceNames, |
@@ -359,11 +384,6 @@ public class Resolver { |
DartFunction functionNode = node.getFunction(); |
List<DartParameter> parameters = functionNode.getParams(); |
- FunctionType type = (FunctionType) member.getType(); |
- for (TypeVariable typeVariable : type.getTypeVariables()) { |
- context.declare(typeVariable.getElement()); |
- } |
- |
// First declare all normal parameters in the scope, putting them in the |
// scope of the default expressions so we can report better errors. |
for (DartParameter parameter : parameters) { |
@@ -533,6 +553,7 @@ public class Resolver { |
resolveType( |
node.getTypeNode(), |
inStaticContext(currentMethod), |
+ inFactoryContext(currentMethod), |
TypeErrorCode.NO_SUCH_TYPE); |
for (DartVariable variable : node.getVariables()) { |
Elements.setType(resolveVariable(variable, node.getModifiers()), type); |
@@ -572,7 +593,7 @@ public class Resolver { |
MethodElement previousFunction = innermostFunction; |
innermostFunction = element; |
DartFunction functionNode = x.getFunction(); |
- resolveFunction(functionNode, element, null); |
+ resolveFunction(functionNode, element); |
resolve(functionNode.getBody()); |
innermostFunction = previousFunction; |
getContext().popScope(); |
@@ -819,7 +840,8 @@ public class Resolver { |
@Override |
public Element visitTypeNode(DartTypeNode x) { |
- return resolveType(x, inStaticContext(currentMethod), ResolverErrorCode.NO_SUCH_TYPE).getElement(); |
+ return resolveType(x, inStaticContext(currentMethod), inFactoryContext(currentMethod), |
+ ResolverErrorCode.NO_SUCH_TYPE).getElement(); |
} |
@Override |
@@ -992,10 +1014,11 @@ public class Resolver { |
Element element = x.getConstructor().accept(getContext().new Selector() { |
// Only 'new' expressions can have a type in a property access. |
- @Override public Element visitTypeNode(DartTypeNode type) { |
- return recordType( |
- type, |
- resolveType(type, inStaticContext(currentMethod), ResolverErrorCode.NO_SUCH_TYPE)); |
+ @Override |
+ public Element visitTypeNode(DartTypeNode type) { |
+ return recordType(type, resolveType(type, inStaticContext(currentMethod), |
+ inFactoryContext(currentMethod), |
+ ResolverErrorCode.NO_SUCH_TYPE)); |
} |
@Override public Element visitPropertyAccess(DartPropertyAccess node) { |
@@ -1117,7 +1140,7 @@ public class Resolver { |
} |
onError( |
errorTargetNode, |
- ResolverErrorCode.FACTORY_CONSTRUCTOR_UNRESOLVED, |
+ ResolverErrorCode.DEFAULT_CONSTRUCTOR_UNRESOLVED, |
expectedFactoryConstructorName, |
defaultClassName); |
return null; |
@@ -1371,6 +1394,7 @@ public class Resolver { |
node, |
typeArgs, |
inStaticContext(currentMethod), |
+ inFactoryContext(currentMethod), |
ResolverErrorCode.NO_SUCH_TYPE); |
// instantiateParametersType() will complain for wrong number of parameters (!=2) |
recordType(node, type); |
@@ -1387,6 +1411,7 @@ public class Resolver { |
node, |
typeArgs, |
inStaticContext(currentMethod), |
+ inFactoryContext(currentMethod), |
ResolverErrorCode.NO_SUCH_TYPE); |
// instantiateParametersType() will complain for wrong number of parameters (!=1) |
recordType(node, type); |
@@ -1521,8 +1546,15 @@ public class Resolver { |
} |
private boolean inStaticContext(Element element) { |
- return element == null || Elements.isTopLevel(element) |
- || element.getModifiers().isStatic() || element.getModifiers().isFactory(); |
+ return element == null || Elements.isTopLevel(element) |
+ || element.getModifiers().isStatic() || element.getModifiers().isFactory(); |
+ } |
+ |
+ private boolean inFactoryContext(Element element) { |
+ if (element != null) { |
+ return element.getModifiers().isFactory(); |
+ } |
+ return false; |
} |
@Override |
@@ -1530,6 +1562,11 @@ public class Resolver { |
return inStaticContext(currentMethod); |
} |
+ @Override |
+ boolean isFactoryContext() { |
+ return inFactoryContext(currentMethod); |
+ } |
+ |
boolean isStaticContextOrInitializer() { |
return inStaticContext(currentMethod) || inInitializer; |
} |