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

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

Issue 10828355: Issue 4289. Test that arguments are bound to positional, optional and named parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Prepare for making optional parameter not named Created 8 years, 4 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 a98d7083c2fb30048f689cd5ff821ffed6896ade..7539ecd4f328e8c31f6c2d63ea7350c704d2cdc0 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -987,6 +987,29 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
}
+ // Check optional parameters.
+ // TODO(scheglov) currently this block does not work,
+ // because we handle all optional parameter as named
+ {
+ Map<String, Type> optionalParameterTypes = ftype.getOptionalParameterTypes();
+ Iterator<Entry<String, Type>> optionalParameterTypesIterator =
+ optionalParameterTypes.entrySet().iterator();
+ while (optionalParameterTypesIterator.hasNext()
+ && argumentTypes.hasNext()) {
+ Entry<String, Type> namedEntry = optionalParameterTypesIterator.next();
+ Type optionalType = namedEntry.getValue();
+ optionalType.getClass(); // quick null check
+ Type argumentType = argumentTypes.next();
+ argumentType.getClass(); // quick null check
+ DartExpression argumentNode = argumentNodes.get(argumentIndex);
+ argumentNode.setInvocationParameterId(argumentIndex);
+ if (checkAssignable(argumentNode, optionalType, argumentType)) {
+ inferFunctionLiteralParametersTypes(argumentNode, optionalType);
+ }
+ argumentIndex++;
+ }
+ }
+
// Check named parameters.
{
Set<String> usedNamedParametersPositional = Sets.newHashSet();
@@ -1021,6 +1044,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
DartExpression argumentNode = namedExpression.getExpression();
// Prepare parameter name.
String parameterName = namedExpression.getName().getName();
+ namedExpression.setInvocationParameterId(parameterName);
argumentNode.setInvocationParameterId(parameterName);
if (usedNamedParametersPositional.contains(parameterName)) {
onError(namedExpression, TypeErrorCode.DUPLICATE_NAMED_ARGUMENT);

Powered by Google App Engine
This is Rietveld 408576698