Index: pkg/compiler/lib/src/typechecker.dart |
diff --git a/pkg/compiler/lib/src/typechecker.dart b/pkg/compiler/lib/src/typechecker.dart |
index e7d66cef0e0d71b7a5edee1523b749060058a5af..6306b197c69578d8759fbd0357d667f12be42132 100644 |
--- a/pkg/compiler/lib/src/typechecker.dart |
+++ b/pkg/compiler/lib/src/typechecker.dart |
@@ -652,7 +652,9 @@ class TypeCheckerVisitor extends Visitor<ResolutionDartType> { |
if (Elements.isUnresolved(element)) return const ResolutionDynamicType(); |
if (element.isGenerativeConstructor) { |
type = const ResolutionDynamicType(); |
- returnType = const ResolutionVoidType(); |
+ // TODO(floitsch): would be nice to have the voidType directly on |
+ // commonElements. |
+ returnType = new ResolutionVoidType(commonElements.objectClass); |
element.functionSignature.forEachParameter((ParameterElement parameter) { |
if (parameter.isInitializingFormal) { |
@@ -1693,6 +1695,10 @@ class TypeCheckerVisitor extends Visitor<ResolutionDartType> { |
final Node expression = node.expression; |
+ // TODO(floitsch): would be nice if the voidType was directly accessible |
+ // from `commonElements`. |
+ ResolutionVoidType voidType = |
+ new ResolutionVoidType(commonElements.objectClass); |
// Executing a return statement return e; [...] It is a static type warning |
// if the type of e may not be assigned to the declared return type of the |
// immediately enclosing function. |
@@ -1706,8 +1712,10 @@ class TypeCheckerVisitor extends Visitor<ResolutionDartType> { |
commonElements.futureType(types.flatten(expressionType)); |
expressionType = futureOfFlattenedType; |
} |
+ // TODO(floitsch): this is probably where we want to have the checks |
+ // that `void` must not have a `return` unless it returns void. |
if (expectedReturnType.isVoid && |
- !types.isAssignable(expressionType, const ResolutionVoidType())) { |
+ !types.isAssignable(expressionType, voidType)) { |
reportTypeWarning(expression, MessageKind.RETURN_VALUE_IN_VOID); |
} else { |
checkAssignable(expression, expressionType, expectedReturnType); |
@@ -1715,8 +1723,10 @@ class TypeCheckerVisitor extends Visitor<ResolutionDartType> { |
} |
} else if (currentAsyncMarker != AsyncMarker.SYNC) { |
// `return;` is allowed. |
- } else if (!types.isAssignable( |
- expectedReturnType, const ResolutionVoidType())) { |
+ } else if (!types.isAssignable(expectedReturnType, voidType)) { |
+ // TODO(floitsch): this is probably where we want to have the checks |
+ // that `void` must not have a `return` unless it returns void. |
+ |
// Let f be the function immediately enclosing a return statement of the |
// form 'return;' It is a static warning if both of the following |
// conditions hold: |