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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_types.dart

Issue 12385079: Handle void correctly in function subtyping. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 9 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
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/dart_types.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_types.dart b/sdk/lib/_internal/compiler/implementation/dart_types.dart
index 81539d2400b0df14ec9c0b1390c10c684981df32..cfea7a5d5dc3656140380fcc6b4ad3a79f1c081c 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -672,18 +672,18 @@ class FunctionType extends DartType {
}
int get hashCode {
- int hash = 17 * element.hashCode + 3 * returnType.hashCode;
+ int hash = 3 * returnType.hashCode;
for (DartType parameter in parameterTypes) {
- hash = 17 * hash + 3 * parameter.hashCode;
+ hash = 17 * hash + 5 * parameter.hashCode;
}
for (DartType parameter in optionalParameterTypes) {
- hash = 17 * hash + 3 * parameter.hashCode;
+ hash = 19 * hash + 7 * parameter.hashCode;
}
for (SourceString name in namedParameters) {
- hash = 17 * hash + 3 * name.hashCode;
+ hash = 23 * hash + 11 * name.hashCode;
}
for (DartType parameter in namedParameterTypes) {
- hash = 17 * hash + 3 * parameter.hashCode;
+ hash = 29 * hash + 13 * parameter.hashCode;
}
return hash;
}
@@ -858,8 +858,11 @@ abstract class DartTypeVisitor<R, A> {
class SubtypeVisitor extends DartTypeVisitor<bool, DartType> {
final Compiler compiler;
final DynamicType dynamicType;
+ final VoidType voidType;
- SubtypeVisitor(Compiler this.compiler, DynamicType this.dynamicType);
+ SubtypeVisitor(Compiler this.compiler,
+ DynamicType this.dynamicType,
+ VoidType this.voidType);
bool isSubtype(DartType t, DartType s) {
if (identical(t, s) ||
@@ -929,8 +932,10 @@ class SubtypeVisitor extends DartTypeVisitor<bool, DartType> {
sps = sps.tail;
}
if (!tps.isEmpty || !sps.isEmpty) return false;
- // TODO(johnniwinther): Handle the void type correctly.
- if (!isAssignable(tf.returnType, sf.returnType)) return false;
+ if (!identical(sf.returnType, voidType) &&
+ !isAssignable(tf.returnType, sf.returnType)) {
+ return false;
+ }
if (!sf.namedParameters.isEmpty) {
// Since named parameters are globally ordered we can determine the
// subset relation with a linear search for [:sf.NamedParameters:]
@@ -992,7 +997,8 @@ class Types {
VoidType voidType = new VoidType(new VoidElementX(library));
DynamicType dynamicType = new DynamicType(dynamicElement);
dynamicElement.rawType = dynamicElement.thisType = dynamicType;
- SubtypeVisitor subtypeVisitor = new SubtypeVisitor(compiler, dynamicType);
+ SubtypeVisitor subtypeVisitor =
+ new SubtypeVisitor(compiler, dynamicType, voidType);
return new Types.internal(compiler, voidType, dynamicType, subtypeVisitor);
}
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698