| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'package:expect/expect.dart'; | |
| 6 import "package:async_helper/async_helper.dart"; | |
| 7 | |
| 8 import 'compiler_helper.dart'; | |
| 9 import 'parser_helper.dart'; | |
| 10 | |
| 11 const String TEST = ''' | |
| 12 testFunctionStatement() { | |
| 13 var res; | |
| 14 closure(a) => res = a; | |
| 15 closure(42); | |
| 16 return res; | |
| 17 } | |
| 18 | |
| 19 testFunctionExpression() { | |
| 20 var res; | |
| 21 var closure = (a) => res = a; | |
| 22 closure(42); | |
| 23 return res; | |
| 24 } | |
| 25 | |
| 26 var staticField; | |
| 27 | |
| 28 testStoredInStatic() { | |
| 29 var res; | |
| 30 closure(a) => res = a; | |
| 31 staticField = closure; | |
| 32 staticField(42); | |
| 33 return res; | |
| 34 } | |
| 35 | |
| 36 class A { | |
| 37 var field; | |
| 38 A(this.field); | |
| 39 } | |
| 40 | |
| 41 testStoredInInstance() { | |
| 42 var res; | |
| 43 closure(a) => res = a; | |
| 44 var a = new A(closure); | |
| 45 a.field(42); | |
| 46 return res; | |
| 47 } | |
| 48 | |
| 49 foo(closure) { | |
| 50 closure(42); | |
| 51 } | |
| 52 | |
| 53 testPassedInParameter() { | |
| 54 var res; | |
| 55 closure(a) => res = a; | |
| 56 foo(closure); | |
| 57 return res; | |
| 58 } | |
| 59 | |
| 60 main() { | |
| 61 testFunctionStatement(); | |
| 62 testFunctionExpression(); | |
| 63 testStoredInStatic(); | |
| 64 testStoredInInstance(); | |
| 65 testPassedInParameter(); | |
| 66 } | |
| 67 '''; | |
| 68 | |
| 69 void main() { | |
| 70 Uri uri = new Uri(scheme: 'source'); | |
| 71 var compiler = compilerFor(TEST, uri); | |
| 72 asyncTest(() => compiler.runCompiler(uri).then((_) { | |
| 73 var typesTask = compiler.typesTask; | |
| 74 var typesInferrer = typesTask.typesInferrer; | |
| 75 | |
| 76 checkType(String name, type) { | |
| 77 var element = findElement(compiler, name); | |
| 78 var mask = typesInferrer.getReturnTypeOfElement(element); | |
| 79 Expect.equals(type.nullable(), mask.simplify(compiler), name); | |
| 80 } | |
| 81 | |
| 82 checkType('testFunctionStatement', typesTask.uint31Type); | |
| 83 checkType('testFunctionExpression', typesTask.uint31Type); | |
| 84 checkType('testStoredInInstance', typesTask.uint31Type); | |
| 85 checkType('testStoredInStatic', typesTask.uint31Type); | |
| 86 checkType('testPassedInParameter', typesTask.uint31Type); | |
| 87 })); | |
| 88 } | |
| OLD | NEW |