| 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 library type_variable_occurrence_test; | 5 library type_variable_occurrence_test; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import 'type_test_helper.dart'; | 9 import 'type_test_helper.dart'; |
| 10 import 'package:compiler/src/dart_types.dart'; | 10 import 'package:compiler/src/dart_types.dart'; |
| 11 import "package:compiler/src/elements/elements.dart" | 11 import "package:compiler/src/elements/elements.dart" show Element, ClassElement; |
| 12 show Element, ClassElement; | |
| 13 | 12 |
| 14 void main() { | 13 void main() { |
| 15 testTypeVariableOccurrence(); | 14 testTypeVariableOccurrence(); |
| 16 } | 15 } |
| 17 | 16 |
| 18 testTypeVariableOccurrence() { | 17 testTypeVariableOccurrence() { |
| 19 asyncTest(() => TypeEnvironment.create(r""" | 18 asyncTest(() => TypeEnvironment.create(r""" |
| 20 typedef S Typedef1<S>(); | 19 typedef S Typedef1<S>(); |
| 21 typedef void Typedef2<S>(S s); | 20 typedef void Typedef2<S>(S s); |
| 22 typedef void Typedef3<S>(A<S> a); | 21 typedef void Typedef3<S>(A<S> a); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 void method1() {} | 46 void method1() {} |
| 48 T method2() => null; | 47 T method2() => null; |
| 49 A<T> method3() => null; | 48 A<T> method3() => null; |
| 50 void method4(T t) {} | 49 void method4(T t) {} |
| 51 void method5(A<T> t) {} | 50 void method5(A<T> t) {} |
| 52 void method6(void foo(T t)) {} | 51 void method6(void foo(T t)) {} |
| 53 void method7([T t]) {} | 52 void method7([T t]) {} |
| 54 void method8({T t}) {} | 53 void method8({T t}) {} |
| 55 } | 54 } |
| 56 """).then((env) { | 55 """).then((env) { |
| 56 ClassElement A = env.getElement('A'); |
| 57 | 57 |
| 58 ClassElement A = env.getElement('A'); | 58 expect(bool expectResult, String memberName) { |
| 59 DartType memberType = env.getMemberType(A, memberName); |
| 60 TypeVariableType typeVariable = memberType.typeVariableOccurrence; |
| 61 if (expectResult) { |
| 62 Expect.isNotNull(typeVariable); |
| 63 Expect.equals(A, Types.getClassContext(memberType)); |
| 64 } else { |
| 65 Expect.isNull(typeVariable); |
| 66 Expect.isNull(Types.getClassContext(memberType)); |
| 67 } |
| 68 } |
| 59 | 69 |
| 60 expect(bool expectResult, String memberName) { | 70 // int field1; |
| 61 DartType memberType = env.getMemberType(A, memberName); | 71 expect(false, 'field1'); |
| 62 TypeVariableType typeVariable = memberType.typeVariableOccurrence; | 72 // T field2; |
| 63 if (expectResult) { | 73 expect(true, 'field2'); |
| 64 Expect.isNotNull(typeVariable); | 74 // A<int> field3; |
| 65 Expect.equals(A, Types.getClassContext(memberType)); | 75 expect(false, 'field3'); |
| 66 } else { | 76 // A<T> field4; |
| 67 Expect.isNull(typeVariable); | 77 expect(true, 'field4'); |
| 68 Expect.isNull(Types.getClassContext(memberType)); | 78 // A<A<int>> field5; |
| 69 } | 79 expect(false, 'field5'); |
| 70 } | 80 // A<A<T>> field6; |
| 81 expect(true, 'field6'); |
| 71 | 82 |
| 72 // int field1; | 83 // Typedef1 field7; |
| 73 expect(false, 'field1'); | 84 expect(false, 'field7'); |
| 74 // T field2; | 85 // Typedef1<int> field8; |
| 75 expect(true, 'field2'); | 86 expect(false, 'field8'); |
| 76 // A<int> field3; | 87 // Typedef1<T> field9; |
| 77 expect(false, 'field3'); | 88 expect(true, 'field9'); |
| 78 // A<T> field4; | 89 // Typedef1<Typedef1<T>> field10; |
| 79 expect(true, 'field4'); | 90 expect(true, 'field10'); |
| 80 // A<A<int>> field5; | |
| 81 expect(false, 'field5'); | |
| 82 // A<A<T>> field6; | |
| 83 expect(true, 'field6'); | |
| 84 | 91 |
| 85 // Typedef1 field7; | 92 // Typedef2 field11; |
| 86 expect(false, 'field7'); | 93 expect(false, 'field11'); |
| 87 // Typedef1<int> field8; | 94 // Typedef2<int> field12; |
| 88 expect(false, 'field8'); | 95 expect(false, 'field12'); |
| 89 // Typedef1<T> field9; | 96 // Typedef2<T> field13; |
| 90 expect(true, 'field9'); | 97 expect(true, 'field13'); |
| 91 // Typedef1<Typedef1<T>> field10; | 98 // Typedef2<Typedef1<T>> field14; |
| 92 expect(true, 'field10'); | 99 expect(true, 'field14'); |
| 93 | 100 |
| 94 // Typedef2 field11; | 101 // Typedef3 field15; |
| 95 expect(false, 'field11'); | 102 expect(false, 'field15'); |
| 96 // Typedef2<int> field12; | 103 // Typedef3<int> field16; |
| 97 expect(false, 'field12'); | 104 expect(false, 'field16'); |
| 98 // Typedef2<T> field13; | 105 // Typedef3<T> field17; |
| 99 expect(true, 'field13'); | 106 expect(true, 'field17'); |
| 100 // Typedef2<Typedef1<T>> field14; | 107 // Typedef3<Typedef1<T>> field18; |
| 101 expect(true, 'field14'); | 108 expect(true, 'field18'); |
| 102 | 109 |
| 103 // Typedef3 field15; | 110 // void method1() {} |
| 104 expect(false, 'field15'); | 111 expect(false, 'method1'); |
| 105 // Typedef3<int> field16; | 112 // T method2() => null; |
| 106 expect(false, 'field16'); | 113 expect(true, 'method2'); |
| 107 // Typedef3<T> field17; | 114 // A<T> method3() => null; |
| 108 expect(true, 'field17'); | 115 expect(true, 'method3'); |
| 109 // Typedef3<Typedef1<T>> field18; | 116 // void method4(T t) {} |
| 110 expect(true, 'field18'); | 117 expect(true, 'method4'); |
| 111 | 118 // void method5(A<T> t) {} |
| 112 // void method1() {} | 119 expect(true, 'method5'); |
| 113 expect(false, 'method1'); | 120 // void method6(void foo(T t)) {} |
| 114 // T method2() => null; | 121 expect(true, 'method6'); |
| 115 expect(true, 'method2'); | 122 // void method7([T t]); |
| 116 // A<T> method3() => null; | 123 expect(true, 'method7'); |
| 117 expect(true, 'method3'); | 124 // void method8({T t}); |
| 118 // void method4(T t) {} | 125 expect(true, 'method8'); |
| 119 expect(true, 'method4'); | 126 })); |
| 120 // void method5(A<T> t) {} | |
| 121 expect(true, 'method5'); | |
| 122 // void method6(void foo(T t)) {} | |
| 123 expect(true, 'method6'); | |
| 124 // void method7([T t]); | |
| 125 expect(true, 'method7'); | |
| 126 // void method8({T t}); | |
| 127 expect(true, 'method8'); | |
| 128 })); | |
| 129 } | 127 } |
| OLD | NEW |