| 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 static foo(a) => topLevel3 = a; | |
| 40 } | |
| 41 | |
| 42 testStoredInInstance() { | |
| 43 var res; | |
| 44 closure(a) => res = a; | |
| 45 var a = new A(closure); | |
| 46 a.field(42); | |
| 47 return res; | |
| 48 } | |
| 49 | |
| 50 foo(closure) { | |
| 51 closure(42); | |
| 52 } | |
| 53 | |
| 54 testPassedInParameter() { | |
| 55 var res; | |
| 56 closure(a) => res = a; | |
| 57 foo(closure); | |
| 58 return res; | |
| 59 } | |
| 60 | |
| 61 var topLevel1; | |
| 62 foo2(a) => topLevel1 = a; | |
| 63 testStaticClosure1() { | |
| 64 var a = foo2; | |
| 65 a(42); | |
| 66 return topLevel1; | |
| 67 } | |
| 68 | |
| 69 var topLevel2; | |
| 70 bar(a) => topLevel2 = a; | |
| 71 testStaticClosure2() { | |
| 72 var a = bar; | |
| 73 a(42); | |
| 74 var b = bar; | |
| 75 b(2.5); | |
| 76 return topLevel2; | |
| 77 } | |
| 78 | |
| 79 var topLevel3; | |
| 80 testStaticClosure3() { | |
| 81 var a = A.foo; | |
| 82 a(42); | |
| 83 return topLevel3; | |
| 84 } | |
| 85 | |
| 86 main() { | |
| 87 testFunctionStatement(); | |
| 88 testFunctionExpression(); | |
| 89 testStoredInStatic(); | |
| 90 testStoredInInstance(); | |
| 91 testPassedInParameter(); | |
| 92 testStaticClosure1(); | |
| 93 testStaticClosure2(); | |
| 94 testStaticClosure3(); | |
| 95 } | |
| 96 '''; | |
| 97 | |
| 98 void main() { | |
| 99 Uri uri = new Uri(scheme: 'source'); | |
| 100 var compiler = compilerFor(TEST, uri); | |
| 101 asyncTest(() => compiler.runCompiler(uri).then((_) { | |
| 102 var typesTask = compiler.typesTask; | |
| 103 var typesInferrer = typesTask.typesInferrer; | |
| 104 | |
| 105 checkType(String name, type) { | |
| 106 var element = findElement(compiler, name); | |
| 107 var mask = typesInferrer.getReturnTypeOfElement(element); | |
| 108 Expect.equals(type.nullable(), mask.simplify(compiler), name); | |
| 109 } | |
| 110 | |
| 111 checkType('testFunctionStatement', typesTask.uint31Type); | |
| 112 checkType('testFunctionExpression', typesTask.uint31Type); | |
| 113 checkType('testStoredInInstance', typesTask.uint31Type); | |
| 114 checkType('testStoredInStatic', typesTask.uint31Type); | |
| 115 checkType('testPassedInParameter', typesTask.uint31Type); | |
| 116 checkType('testStaticClosure1', typesTask.uint31Type); | |
| 117 checkType('testStaticClosure2', typesTask.numType); | |
| 118 checkType('testStaticClosure3', typesTask.uint31Type); | |
| 119 })); | |
| 120 } | |
| OLD | NEW |