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

Unified Diff: lib/compiler/implementation/typechecker.dart

Issue 10387033: Add VoidElement and VoidType to make sure that there is a canonical void type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 7 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 | « lib/compiler/implementation/elements/elements.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/typechecker.dart
diff --git a/lib/compiler/implementation/typechecker.dart b/lib/compiler/implementation/typechecker.dart
index 6326ddb9f7667bc685b61b074ac6dd45032556bb..8c69f55ddf23a1076295f490ad9c5933d78a8b98 100644
--- a/lib/compiler/implementation/typechecker.dart
+++ b/lib/compiler/implementation/typechecker.dart
@@ -60,6 +60,12 @@ class StatementType implements Type {
String toString() => stringName;
}
+class VoidType implements Type {
+ const VoidType(this.element);
+ SourceString get name() => Types.VOID;
+ final VoidElement element;
+}
+
class InterfaceType implements Type {
final Element element;
final Link<Type> arguments;
@@ -111,7 +117,7 @@ class Types {
static final OBJECT = const SourceString('Object');
static final LIST = const SourceString('List');
- final InterfaceType voidType;
+ final VoidType voidType;
final InterfaceType dynamicType;
Types(Element dynamicElement)
@@ -119,7 +125,7 @@ class Types {
// TODO(karlklose): should we have a class Void?
Types.with(Element dynamicElement, LibraryElement library)
- : voidType = new InterfaceType(new ClassElement(VOID, library)),
+ : voidType = new VoidType(new VoidElement(library)),
dynamicType = new InterfaceType(dynamicElement);
Type lookup(SourceString s) {
@@ -135,7 +141,9 @@ class Types {
bool isSubtype(Type t, Type s) {
if (t === s || t === dynamicType || s === dynamicType ||
s.name == OBJECT) return true;
- if (t is InterfaceType) {
+ if (t is VoidType) {
+ return false;
+ } else if (t is InterfaceType) {
if (s is !InterfaceType) return false;
ClassElement tc = t.element;
if (tc === s.element) return true;
@@ -578,8 +586,7 @@ class TypeCheckerVisitor implements Visitor<Type> {
/** Dart Programming Language Specification: 11.10 Return */
Type visitReturn(Return node) {
final expression = node.expression;
- final isVoidFunction =
- (expectedReturnType.element === compiler.types.voidType.element);
+ final isVoidFunction = (expectedReturnType === types.voidType);
// 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
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698