| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class TypeCheckerTask extends CompilerTask { | 5 class TypeCheckerTask extends CompilerTask { |
| 6 TypeCheckerTask(Compiler compiler) : super(compiler); | 6 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 7 String get name() => "Type checker"; | 7 String get name() => "Type checker"; |
| 8 | 8 |
| 9 static final bool LOG_FAILURES = false; | 9 static final bool LOG_FAILURES = false; |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 static final LIST = const SourceString('List'); | 111 static final LIST = const SourceString('List'); |
| 112 | 112 |
| 113 final InterfaceType voidType; | 113 final InterfaceType voidType; |
| 114 final InterfaceType dynamicType; | 114 final InterfaceType dynamicType; |
| 115 | 115 |
| 116 Types(Element dynamicElement) | 116 Types(Element dynamicElement) |
| 117 : this.with(dynamicElement, new LibraryElement(new Script(null, null))); | 117 : this.with(dynamicElement, new LibraryElement(new Script(null, null))); |
| 118 | 118 |
| 119 // TODO(karlklose): should we have a class Void? | 119 // TODO(karlklose): should we have a class Void? |
| 120 Types.with(Element dynamicElement, LibraryElement library) | 120 Types.with(Element dynamicElement, LibraryElement library) |
| 121 : voidType = new InterfaceType(VOID, new ClassElement(VOID, library)), | 121 : voidType = new InterfaceType(VOID, new ClassElement(VOID, library)), |
| 122 dynamicType = new InterfaceType(DYNAMIC, dynamicElement); | 122 dynamicType = new InterfaceType(DYNAMIC, dynamicElement); |
| 123 | 123 |
| 124 Type lookup(SourceString s) { | 124 Type lookup(SourceString s) { |
| 125 if (VOID == s) { | 125 if (VOID == s) { |
| 126 return voidType; | 126 return voidType; |
| 127 } else if (DYNAMIC == s || s.stringValue === 'var') { | 127 } else if (DYNAMIC == s || s.stringValue === 'var') { |
| 128 return dynamicType; | 128 return dynamicType; |
| 129 } | 129 } |
| 130 return null; | 130 return null; |
| 131 } | 131 } |
| 132 | 132 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 return type; | 570 return type; |
| 571 } | 571 } |
| 572 | 572 |
| 573 Type visitOperator(Operator node) { | 573 Type visitOperator(Operator node) { |
| 574 fail(node, 'internal error'); | 574 fail(node, 'internal error'); |
| 575 } | 575 } |
| 576 | 576 |
| 577 /** Dart Programming Language Specification: 11.10 Return */ | 577 /** Dart Programming Language Specification: 11.10 Return */ |
| 578 Type visitReturn(Return node) { | 578 Type visitReturn(Return node) { |
| 579 final expression = node.expression; | 579 final expression = node.expression; |
| 580 final isVoidFunction = (expectedReturnType === types.voidType); | 580 final isVoidFunction = |
| 581 (expectedReturnType.element === compiler.types.voidType.element); |
| 581 | 582 |
| 582 // Executing a return statement return e; [...] It is a static type warning | 583 // Executing a return statement return e; [...] It is a static type warning |
| 583 // if the type of e may not be assigned to the declared return type of the | 584 // if the type of e may not be assigned to the declared return type of the |
| 584 // immediately enclosing function. | 585 // immediately enclosing function. |
| 585 if (expression !== null) { | 586 if (expression !== null) { |
| 586 final expressionType = analyze(expression); | 587 final expressionType = analyze(expression); |
| 587 if (isVoidFunction | 588 if (isVoidFunction |
| 588 && !types.isAssignable(expressionType, types.voidType)) { | 589 && !types.isAssignable(expressionType, types.voidType)) { |
| 589 reportTypeWarning(expression, MessageKind.RETURN_VALUE_IN_VOID, | 590 reportTypeWarning(expression, MessageKind.RETURN_VALUE_IN_VOID, |
| 590 [expressionType]); | 591 [expressionType]); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 } | 728 } |
| 728 | 729 |
| 729 visitCatchBlock(CatchBlock node) { | 730 visitCatchBlock(CatchBlock node) { |
| 730 fail(node); | 731 fail(node); |
| 731 } | 732 } |
| 732 | 733 |
| 733 visitTypedef(Typedef node) { | 734 visitTypedef(Typedef node) { |
| 734 fail(node); | 735 fail(node); |
| 735 } | 736 } |
| 736 } | 737 } |
| OLD | NEW |