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

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

Issue 10544156: Adds warning when a named argument is specified, but a positional argument is missing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: # Created 8 years, 6 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 c7815476b0e5446c4e45510b222881d4cb364309..c2bc54e3c06498d0b4ba9016568e5d42da211af1 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -849,19 +849,27 @@ public class TypeAnalyzer implements DartCompilationPhase {
Iterator<Type> argumentTypes, FunctionType ftype) {
int argumentIndex = 0;
// Check positional parameters.
- List<Type> parameterTypes = ftype.getParameterTypes();
- for (Type parameterType : parameterTypes) {
- parameterType.getClass(); // quick null check
- if (argumentTypes.hasNext()) {
- Type argumentType = argumentTypes.next();
- argumentType.getClass(); // quick null check
- checkAssignable(argumentNodes.get(argumentIndex), parameterType, argumentType);
- argumentIndex++;
- } else {
- onError(diagnosticNode, TypeErrorCode.MISSING_ARGUMENT, parameterType);
- return ftype.getReturnType();
+ {
+ List<Type> parameterTypes = ftype.getParameterTypes();
+ for (Type parameterType : parameterTypes) {
+ parameterType.getClass(); // quick null check
+ if (argumentTypes.hasNext()) {
+ Type argumentType = argumentTypes.next();
+ argumentType.getClass(); // quick null check
+ DartExpression argumentNode = argumentNodes.get(argumentIndex);
+ if (argumentNode instanceof DartNamedExpression) {
+ onError(argumentNode, TypeErrorCode.EXPECTED_POSITIONAL_ARGUMENT, parameterType);
+ return ftype.getReturnType();
+ }
+ checkAssignable(argumentNodes.get(argumentIndex), parameterType, argumentType);
+ argumentIndex++;
+ } else {
+ onError(diagnosticNode, TypeErrorCode.MISSING_ARGUMENT, parameterType);
+ return ftype.getReturnType();
+ }
}
}
+
// Check named parameters.
{
Set<String> usedNamedParametersPositional = Sets.newHashSet();

Powered by Google App Engine
This is Rietveld 408576698