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

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

Issue 10509012: Issue 3272. Void can be assigned to Dynamic (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
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 72188ed21b731815613ae7d6e77e746a1982d1ca..a0715e22e4fb1474ee028fffd0fd4d3386bc96f8 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -709,10 +709,18 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
private boolean checkAssignable(Type targetType, DartExpression node) {
- Type nodeType = nonVoidTypeOf(node);
+ // analyze "node"
+ Type nodeType = typeOf(node);
+ // target is Dynamic, any source type is good, even "void"
+ if (TypeKind.of(targetType) == TypeKind.DYNAMIC) {
+ return true;
+ }
+ // source was Dynamic
if (hasInferredType(node)) {
return true;
}
+ // OK, check types
+ checkNonVoid(node, nodeType);
return checkAssignable(node, targetType, nodeType);
}
@@ -986,10 +994,17 @@ public class TypeAnalyzer implements DartCompilationPhase {
*/
private Type nonVoidTypeOf(DartNode node) {
Type type = typeOf(node);
+ return checkNonVoid(node, type);
+ }
+
+ /**
+ * @return the given {@link Type}, registering an error if it is unresolved or void.
+ */
+ private Type checkNonVoid(HasSourceInfo errorTarget, Type type) {
switch (TypeKind.of(type)) {
case VOID:
case NONE:
- return typeError(node, TypeErrorCode.VOID);
+ return typeError(errorTarget, TypeErrorCode.VOID);
default:
return type;
}
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698