Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'compiler_helper.dart'; | 5 import 'compiler_helper.dart'; |
| 6 | 6 |
| 7 const String TEST = """ | 7 const String TEST = """ |
| 8 returnInt1() { | 8 returnInt1() { |
| 9 var a = 42; | 9 var a = 42; |
| 10 var f = () { | 10 var f = () { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 var g = () { | 37 var g = () { |
| 38 a = 'foo'; | 38 a = 'foo'; |
| 39 }; | 39 }; |
| 40 return a; | 40 return a; |
| 41 } | 41 } |
| 42 | 42 |
| 43 returnInt3() { | 43 returnInt3() { |
| 44 var a = 42; | 44 var a = 42; |
| 45 if (a == 53) { | 45 if (a == 53) { |
| 46 var f = () { | 46 var f = () { |
| 47 a = 32; | 47 return a; |
| 48 }; | 48 }; |
| 49 } | 49 } |
| 50 return a; | 50 return a; |
| 51 } | 51 } |
| 52 | 52 |
| 53 returnDyn3() { | 53 returnDyn3() { |
| 54 var a = 42; | 54 var a = 42; |
| 55 if (a == 53) { | 55 if (a == 53) { |
| 56 var f = () { | 56 var f = () { |
| 57 a = 'foo'; | 57 a = 'foo'; |
| 58 }; | 58 }; |
| 59 } | 59 } |
| 60 return a; | 60 return a; |
| 61 } | 61 } |
| 62 | 62 |
| 63 returnInt4() { | |
| 64 var a = 42; | |
| 65 g() { return a; } | |
| 66 return g(); | |
| 67 } | |
| 68 | |
| 63 main() { | 69 main() { |
| 64 returnInt1(); | 70 returnInt1(); |
| 65 returnDyn1(); | 71 returnDyn1(); |
| 66 returnInt2(); | 72 returnInt2(); |
| 67 returnDyn2(); | 73 returnDyn2(); |
| 68 returnInt3(); | 74 returnInt3(); |
| 69 returnDyn3(); | 75 returnDyn3(); |
| 76 returnInt4(); | |
| 70 } | 77 } |
| 71 """; | 78 """; |
| 72 | 79 |
| 73 | 80 |
| 74 void main() { | 81 void main() { |
| 75 Uri uri = new Uri.fromComponents(scheme: 'source'); | 82 Uri uri = new Uri.fromComponents(scheme: 'source'); |
| 76 var compiler = compilerFor(TEST, uri); | 83 var compiler = compilerFor(TEST, uri); |
| 77 compiler.runCompiler(uri); | 84 compiler.runCompiler(uri); |
| 78 var typesInferrer = compiler.typesTask.typesInferrer; | 85 var typesInferrer = compiler.typesTask.typesInferrer; |
| 79 | 86 |
| 80 checkReturn(String name, type) { | 87 checkReturn(String name, type) { |
| 81 var element = findElement(compiler, name); | 88 var element = findElement(compiler, name); |
| 82 Expect.equals(type, typesInferrer.returnTypeOf[element]); | 89 Expect.equals(type, typesInferrer.returnTypeOf[element]); |
| 83 } | 90 } |
| 84 | 91 |
| 85 checkReturn('returnInt1', compiler.intClass); | 92 checkReturn('returnInt1', compiler.intClass); |
| 86 checkReturn('returnInt2', compiler.intClass); | 93 // TODO(ngeoffray): We don't use types of mutated captured |
|
kasperl
2013/03/05 08:26:44
So you'd like to fix this to make returnInt2 retur
ngeoffray
2013/03/05 09:02:31
Depends on the TODO I added in the types inferrer:
| |
| 94 // variables anymore, because they could lead to optimistic results | |
| 95 // needing to be re-analyzed. | |
| 96 checkReturn('returnInt2', compiler.dynamicClass); | |
| 87 checkReturn('returnInt3', compiler.intClass); | 97 checkReturn('returnInt3', compiler.intClass); |
| 98 checkReturn('returnInt4', compiler.intClass); | |
| 88 | 99 |
| 89 checkReturn('returnDyn1', compiler.dynamicClass); | 100 checkReturn('returnDyn1', compiler.dynamicClass); |
| 90 checkReturn('returnDyn2', compiler.dynamicClass); | 101 checkReturn('returnDyn2', compiler.dynamicClass); |
| 91 checkReturn('returnDyn3', compiler.dynamicClass); | 102 checkReturn('returnDyn3', compiler.dynamicClass); |
| 92 | |
| 93 print(typesInferrer.returnTypeOf); | |
| 94 } | 103 } |
| OLD | NEW |