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

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

Issue 11309011: Issue 4289. Separate optional positional and named parameters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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/Types.java
diff --git a/compiler/java/com/google/dart/compiler/type/Types.java b/compiler/java/com/google/dart/compiler/type/Types.java
index 43d6813adf6a411fbd7cb9d454da1998b82675cb..174ca8a5be9af9e4a9135cf62411111235c421d2 100644
--- a/compiler/java/com/google/dart/compiler/type/Types.java
+++ b/compiler/java/com/google/dart/compiler/type/Types.java
@@ -355,6 +355,27 @@ public class Types {
return false;
}
}
+
+ {
+ Map<String, Type> sOpti = s.getOptionalParameterTypes();
+ Map<String, Type> tOpti = t.getOptionalParameterTypes();
+ if (tOpti.size() < sOpti.size()) {
+ return false;
+ }
+ Iterator<Entry<String, Type>> tList = tOpti.entrySet().iterator();
+ Iterator<Entry<String, Type>> sList = sOpti.entrySet().iterator();
+ while (sList.hasNext()) {
+ if (!tList.hasNext()) {
+ return false;
+ }
+ Entry<String, Type> sEntry = sList.next();
+ Entry<String, Type> tEntry = tList.next();
+ if (!isAssignable(tEntry.getValue(), sEntry.getValue())) {
+ return false;
+ }
+ }
+ }
+
Map<String, Type> tNamed = t.getNamedParameterTypes();
Map<String, Type> sNamed = s.getNamedParameterTypes();
if (tNamed.isEmpty() && !sNamed.isEmpty()) {
@@ -366,23 +387,34 @@ public class Types {
if (!sNamed.isEmpty()) {
LinkedHashMap<String,Type> tMap = (LinkedHashMap<String, Type>)(tNamed);
LinkedHashMap<String,Type> sMap = (LinkedHashMap<String, Type>)(sNamed);
- Iterator<Entry<String, Type>> tList = tMap.entrySet().iterator();
- Iterator<Entry<String, Type>> sList = sMap.entrySet().iterator();
- // t named parameters must start with the named parameters of s
- while (sList.hasNext()) {
- if (!tList.hasNext()) {
- return false;
- }
- Entry<String, Type> sEntry = sList.next();
- Entry<String, Type> tEntry = tList.next();
- if (!sEntry.getKey().equals(tEntry.getKey())) {
- return false;
- }
- // Classic: parameter types are contravariant; Dart: assignable.
- if (!isAssignable(tEntry.getValue(), sEntry.getValue())) {
+ if (!tMap.keySet().containsAll(sMap.keySet())) {
+ return false;
+ }
+ for (Entry<String, Type> entry : sMap.entrySet()) {
+ String name = entry.getKey();
+ Type sType = sMap.get(name);
+ Type tType = tMap.get(name);
+ if (!isAssignable(tType, sType)) {
return false;
}
}
+// Iterator<Entry<String, Type>> tList = tMap.entrySet().iterator();
Brian Wilkerson 2012/10/27 00:09:39 Is there any reason not to delete the commented ou
+// Iterator<Entry<String, Type>> sList = sMap.entrySet().iterator();
+// // t named parameters must start with the named parameters of s
+// while (sList.hasNext()) {
+// if (!tList.hasNext()) {
+// return false;
+// }
+// Entry<String, Type> sEntry = sList.next();
+// Entry<String, Type> tEntry = tList.next();
+// if (!sEntry.getKey().equals(tEntry.getKey())) {
+// return false;
+// }
+// // Classic: parameter types are contravariant; Dart: assignable.
+// if (!isAssignable(tEntry.getValue(), sEntry.getValue())) {
+// return false;
+// }
+// }
}
// Classic: parameter types are contravariant; Dart: assignable.

Powered by Google App Engine
This is Rietveld 408576698