| 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 least_upper_bound_test; | 5 library least_upper_bound_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 'package:compiler/src/elements/resolution_types.dart'; | 9 import 'package:compiler/src/elements/resolution_types.dart'; |
| 10 import 'package:compiler/src/elements/elements.dart' show Element, ClassElement; | 10 import 'package:compiler/src/elements/elements.dart' show Element, ClassElement; |
| 11 | 11 |
| 12 import 'type_test_helper.dart'; | 12 import 'type_test_helper.dart'; |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 testInterface1(); | 15 testInterface1(); |
| 16 testInterface2(); | 16 testInterface2(); |
| 17 testGeneric(); | 17 testGeneric(); |
| 18 testMixin(); | 18 testMixin(); |
| 19 testFunction(); | 19 testFunction(); |
| 20 testTypeVariable(); | 20 testTypeVariable(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void testInterface1() { | 23 void testInterface1() { |
| 24 asyncTest(() => TypeEnvironment.create(r""" | 24 asyncTest(() => TypeEnvironment.create(r""" |
| 25 class A {} // A and B have equal depth. | 25 class A {} // A and B have equal depth. |
| 26 class B {} | 26 class B {} |
| 27 class I implements A, B {} | 27 class I implements A, B {} |
| 28 class J implements A, B {} | 28 class J implements A, B {} |
| 29 """).then((env) { | 29 """).then((env) { |
| 30 DartType Object_ = env['Object']; | 30 ResolutionDartType Object_ = env['Object']; |
| 31 DartType A = env['A']; | 31 ResolutionDartType A = env['A']; |
| 32 DartType B = env['B']; | 32 ResolutionDartType B = env['B']; |
| 33 DartType I = env['I']; | 33 ResolutionDartType I = env['I']; |
| 34 DartType J = env['J']; | 34 ResolutionDartType J = env['J']; |
| 35 | 35 |
| 36 checkLub(DartType a, DartType b, DartType expect) { | 36 checkLub(ResolutionDartType a, ResolutionDartType b, |
| 37 DartType lub = env.computeLeastUpperBound(a, b); | 37 ResolutionDartType expect) { |
| 38 ResolutionDartType lub = env.computeLeastUpperBound(a, b); |
| 38 Expect.equals( | 39 Expect.equals( |
| 39 expect, lub, 'Unexpected lub($a,$b) = $lub, expected $expect.'); | 40 expect, lub, 'Unexpected lub($a,$b) = $lub, expected $expect.'); |
| 40 } | 41 } |
| 41 | 42 |
| 42 checkLub(Object_, Object_, Object_); | 43 checkLub(Object_, Object_, Object_); |
| 43 checkLub(Object_, A, Object_); | 44 checkLub(Object_, A, Object_); |
| 44 checkLub(Object_, B, Object_); | 45 checkLub(Object_, B, Object_); |
| 45 checkLub(Object_, I, Object_); | 46 checkLub(Object_, I, Object_); |
| 46 checkLub(Object_, J, Object_); | 47 checkLub(Object_, J, Object_); |
| 47 | 48 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 72 } | 73 } |
| 73 | 74 |
| 74 void testInterface2() { | 75 void testInterface2() { |
| 75 asyncTest(() => TypeEnvironment.create(r""" | 76 asyncTest(() => TypeEnvironment.create(r""" |
| 76 class A {} | 77 class A {} |
| 77 class B {} | 78 class B {} |
| 78 class C extends B {} // This makes C have higher depth than A. | 79 class C extends B {} // This makes C have higher depth than A. |
| 79 class I implements A, C {} | 80 class I implements A, C {} |
| 80 class J implements A, C {} | 81 class J implements A, C {} |
| 81 """).then((env) { | 82 """).then((env) { |
| 82 DartType Object_ = env['Object']; | 83 ResolutionDartType Object_ = env['Object']; |
| 83 DartType A = env['A']; | 84 ResolutionDartType A = env['A']; |
| 84 DartType B = env['B']; | 85 ResolutionDartType B = env['B']; |
| 85 DartType C = env['C']; | 86 ResolutionDartType C = env['C']; |
| 86 DartType I = env['I']; | 87 ResolutionDartType I = env['I']; |
| 87 DartType J = env['J']; | 88 ResolutionDartType J = env['J']; |
| 88 | 89 |
| 89 checkLub(DartType a, DartType b, DartType expectedLub) { | 90 checkLub(ResolutionDartType a, ResolutionDartType b, |
| 90 DartType lub = env.computeLeastUpperBound(a, b); | 91 ResolutionDartType expectedLub) { |
| 92 ResolutionDartType lub = env.computeLeastUpperBound(a, b); |
| 91 Expect.equals(expectedLub, lub, | 93 Expect.equals(expectedLub, lub, |
| 92 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); | 94 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); |
| 93 } | 95 } |
| 94 | 96 |
| 95 checkLub(Object_, Object_, Object_); | 97 checkLub(Object_, Object_, Object_); |
| 96 checkLub(Object_, A, Object_); | 98 checkLub(Object_, A, Object_); |
| 97 checkLub(Object_, B, Object_); | 99 checkLub(Object_, B, Object_); |
| 98 checkLub(Object_, C, Object_); | 100 checkLub(Object_, C, Object_); |
| 99 checkLub(Object_, I, Object_); | 101 checkLub(Object_, I, Object_); |
| 100 checkLub(Object_, J, Object_); | 102 checkLub(Object_, J, Object_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 })); | 138 })); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void testGeneric() { | 141 void testGeneric() { |
| 140 asyncTest(() => TypeEnvironment.create(r""" | 142 asyncTest(() => TypeEnvironment.create(r""" |
| 141 class A {} | 143 class A {} |
| 142 class B {} | 144 class B {} |
| 143 class C extends B {} | 145 class C extends B {} |
| 144 class I<T> {} | 146 class I<T> {} |
| 145 """).then((env) { | 147 """).then((env) { |
| 146 DartType Object_ = env['Object']; | 148 ResolutionDartType Object_ = env['Object']; |
| 147 DartType A = env['A']; | 149 ResolutionDartType A = env['A']; |
| 148 DartType B = env['B']; | 150 ResolutionDartType B = env['B']; |
| 149 DartType C = env['C']; | 151 ResolutionDartType C = env['C']; |
| 150 ClassElement I = env.getElement('I'); | 152 ClassElement I = env.getElement('I'); |
| 151 DartType I_A = instantiate(I, [A]); | 153 ResolutionDartType I_A = instantiate(I, [A]); |
| 152 DartType I_B = instantiate(I, [B]); | 154 ResolutionDartType I_B = instantiate(I, [B]); |
| 153 DartType I_C = instantiate(I, [C]); | 155 ResolutionDartType I_C = instantiate(I, [C]); |
| 154 | 156 |
| 155 checkLub(DartType a, DartType b, DartType expectedLub) { | 157 checkLub(ResolutionDartType a, ResolutionDartType b, |
| 156 DartType lub = env.computeLeastUpperBound(a, b); | 158 ResolutionDartType expectedLub) { |
| 159 ResolutionDartType lub = env.computeLeastUpperBound(a, b); |
| 157 Expect.equals(expectedLub, lub, | 160 Expect.equals(expectedLub, lub, |
| 158 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); | 161 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); |
| 159 } | 162 } |
| 160 | 163 |
| 161 checkLub(Object_, Object_, Object_); | 164 checkLub(Object_, Object_, Object_); |
| 162 checkLub(Object_, A, Object_); | 165 checkLub(Object_, A, Object_); |
| 163 checkLub(Object_, B, Object_); | 166 checkLub(Object_, B, Object_); |
| 164 checkLub(Object_, C, Object_); | 167 checkLub(Object_, C, Object_); |
| 165 checkLub(Object_, I_A, Object_); | 168 checkLub(Object_, I_A, Object_); |
| 166 checkLub(Object_, I_B, Object_); | 169 checkLub(Object_, I_B, Object_); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 void testMixin() { | 222 void testMixin() { |
| 220 asyncTest(() => TypeEnvironment.create(r""" | 223 asyncTest(() => TypeEnvironment.create(r""" |
| 221 class A {} | 224 class A {} |
| 222 class B {} | 225 class B {} |
| 223 class C extends B {} | 226 class C extends B {} |
| 224 class D extends C {} // This makes D have higher depth than Object+A. | 227 class D extends C {} // This makes D have higher depth than Object+A. |
| 225 class I extends Object with A, B implements A, D {} | 228 class I extends Object with A, B implements A, D {} |
| 226 class I2 extends Object with A, B implements A, D {} | 229 class I2 extends Object with A, B implements A, D {} |
| 227 class J extends Object with B, A implements A, D {} | 230 class J extends Object with B, A implements A, D {} |
| 228 """).then((env) { | 231 """).then((env) { |
| 229 DartType Object_ = env['Object']; | 232 ResolutionDartType Object_ = env['Object']; |
| 230 DartType A = env['A']; | 233 ResolutionDartType A = env['A']; |
| 231 DartType B = env['B']; | 234 ResolutionDartType B = env['B']; |
| 232 DartType C = env['C']; | 235 ResolutionDartType C = env['C']; |
| 233 DartType D = env['D']; | 236 ResolutionDartType D = env['D']; |
| 234 DartType I = env['I']; | 237 ResolutionDartType I = env['I']; |
| 235 DartType I2 = env['I2']; | 238 ResolutionDartType I2 = env['I2']; |
| 236 DartType J = env['J']; | 239 ResolutionDartType J = env['J']; |
| 237 | 240 |
| 238 checkLub(DartType a, DartType b, DartType expectedLub) { | 241 checkLub(ResolutionDartType a, ResolutionDartType b, |
| 239 DartType lub = env.computeLeastUpperBound(a, b); | 242 ResolutionDartType expectedLub) { |
| 243 ResolutionDartType lub = env.computeLeastUpperBound(a, b); |
| 240 Expect.equals(expectedLub, lub, | 244 Expect.equals(expectedLub, lub, |
| 241 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); | 245 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); |
| 242 } | 246 } |
| 243 | 247 |
| 244 checkLub(Object_, Object_, Object_); | 248 checkLub(Object_, Object_, Object_); |
| 245 checkLub(Object_, A, Object_); | 249 checkLub(Object_, A, Object_); |
| 246 checkLub(Object_, B, Object_); | 250 checkLub(Object_, B, Object_); |
| 247 checkLub(Object_, C, Object_); | 251 checkLub(Object_, C, Object_); |
| 248 checkLub(Object_, D, Object_); | 252 checkLub(Object_, D, Object_); |
| 249 checkLub(Object_, I, Object_); | 253 checkLub(Object_, I, Object_); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 typedef void void__B_C(B a, C b); | 337 typedef void void__B_C(B a, C b); |
| 334 | 338 |
| 335 typedef void void___B([B a]); | 339 typedef void void___B([B a]); |
| 336 typedef void void___B_C([B a, C b]); | 340 typedef void void___B_C([B a, C b]); |
| 337 typedef void void___C_C([C a, C b]); | 341 typedef void void___C_C([C a, C b]); |
| 338 | 342 |
| 339 typedef void void____B({B a}); | 343 typedef void void____B({B a}); |
| 340 typedef void void____B_C({B a, C b}); | 344 typedef void void____B_C({B a, C b}); |
| 341 typedef void void____C_C({C a, C b}); | 345 typedef void void____C_C({C a, C b}); |
| 342 """).then((env) { | 346 """).then((env) { |
| 343 DartType Object_ = env['Object']; | 347 ResolutionDartType Object_ = env['Object']; |
| 344 DartType Function_ = env['Function']; | 348 ResolutionDartType Function_ = env['Function']; |
| 345 DartType dynamic__ = env['dynamic__']; | 349 ResolutionDartType dynamic__ = env['dynamic__']; |
| 346 DartType void__ = env['void__']; | 350 ResolutionDartType void__ = env['void__']; |
| 347 DartType A__ = env['A__']; | 351 ResolutionDartType A__ = env['A__']; |
| 348 DartType B__ = env['B__']; | 352 ResolutionDartType B__ = env['B__']; |
| 349 DartType C__ = env['C__']; | 353 ResolutionDartType C__ = env['C__']; |
| 350 DartType void__A_B = env['void__A_B']; | 354 ResolutionDartType void__A_B = env['void__A_B']; |
| 351 DartType void__A_C = env['void__A_C']; | 355 ResolutionDartType void__A_C = env['void__A_C']; |
| 352 DartType void__B_A = env['void__B_A']; | 356 ResolutionDartType void__B_A = env['void__B_A']; |
| 353 DartType void__B_C = env['void__B_C']; | 357 ResolutionDartType void__B_C = env['void__B_C']; |
| 354 DartType void___B = env['void___B']; | 358 ResolutionDartType void___B = env['void___B']; |
| 355 DartType void___B_C = env['void___B_C']; | 359 ResolutionDartType void___B_C = env['void___B_C']; |
| 356 DartType void___C_C = env['void___C_C']; | 360 ResolutionDartType void___C_C = env['void___C_C']; |
| 357 DartType void____B = env['void____B']; | 361 ResolutionDartType void____B = env['void____B']; |
| 358 DartType void____B_C = env['void____B_C']; | 362 ResolutionDartType void____B_C = env['void____B_C']; |
| 359 DartType void____C_C = env['void____C_C']; | 363 ResolutionDartType void____C_C = env['void____C_C']; |
| 360 | 364 |
| 361 // Types used only for checking results. | 365 // Types used only for checking results. |
| 362 DartType void_ = env['void']; | 366 ResolutionDartType void_ = env['void']; |
| 363 DartType B = env['B']; | 367 ResolutionDartType B = env['B']; |
| 364 DartType C = env['C']; | 368 ResolutionDartType C = env['C']; |
| 365 FunctionType Object__ = env.functionType(Object_, []); | 369 ResolutionFunctionType Object__ = env.functionType(Object_, []); |
| 366 FunctionType void__Object_Object = | 370 ResolutionFunctionType void__Object_Object = |
| 367 env.functionType(void_, [Object_, Object_]); | 371 env.functionType(void_, [Object_, Object_]); |
| 368 FunctionType void__Object_B = env.functionType(void_, [Object_, B]); | 372 ResolutionFunctionType void__Object_B = |
| 369 FunctionType void__Object_C = env.functionType(void_, [Object_, C]); | 373 env.functionType(void_, [Object_, B]); |
| 370 FunctionType void__B_Object = env.functionType(void_, [B, Object_]); | 374 ResolutionFunctionType void__Object_C = |
| 375 env.functionType(void_, [Object_, C]); |
| 376 ResolutionFunctionType void__B_Object = |
| 377 env.functionType(void_, [B, Object_]); |
| 371 | 378 |
| 372 checkLub(DartType a, DartType b, DartType expectedLub) { | 379 checkLub(ResolutionDartType a, ResolutionDartType b, |
| 373 DartType lub = env.computeLeastUpperBound(a, b); | 380 ResolutionDartType expectedLub) { |
| 381 ResolutionDartType lub = env.computeLeastUpperBound(a, b); |
| 374 if (a != b) { | 382 if (a != b) { |
| 375 expectedLub = expectedLub.unaliased; | 383 expectedLub = expectedLub.unaliased; |
| 376 lub = lub.unaliased; | 384 lub = lub.unaliased; |
| 377 } | 385 } |
| 378 Expect.equals( | 386 Expect.equals( |
| 379 expectedLub, | 387 expectedLub, |
| 380 lub, | 388 lub, |
| 381 'Unexpected lub(${a.unaliased},' | 389 'Unexpected lub(${a.unaliased},' |
| 382 '${b.unaliased} = ' | 390 '${b.unaliased} = ' |
| 383 '${lub}, expected ${expectedLub}'); | 391 '${lub}, expected ${expectedLub}'); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 X extends T> {} | 712 X extends T> {} |
| 705 """).then((env) { | 713 """).then((env) { |
| 706 // A B | 714 // A B |
| 707 // | / \ | 715 // | / \ |
| 708 // S T C | 716 // S T C |
| 709 // / \ \ | 717 // / \ \ |
| 710 // V X U | 718 // V X U |
| 711 // / | 719 // / |
| 712 // W | 720 // W |
| 713 | 721 |
| 714 DartType Object_ = env['Object']; | 722 ResolutionDartType Object_ = env['Object']; |
| 715 DartType A = env['A']; | 723 ResolutionDartType A = env['A']; |
| 716 DartType B = env['B']; | 724 ResolutionDartType B = env['B']; |
| 717 DartType C = env['C']; | 725 ResolutionDartType C = env['C']; |
| 718 ClassElement I = env.getElement('I'); | 726 ClassElement I = env.getElement('I'); |
| 719 DartType S = I.typeVariables[0]; | 727 ResolutionDartType S = I.typeVariables[0]; |
| 720 DartType T = I.typeVariables[1]; | 728 ResolutionDartType T = I.typeVariables[1]; |
| 721 DartType U = I.typeVariables[2]; | 729 ResolutionDartType U = I.typeVariables[2]; |
| 722 DartType V = I.typeVariables[3]; | 730 ResolutionDartType V = I.typeVariables[3]; |
| 723 DartType W = I.typeVariables[4]; | 731 ResolutionDartType W = I.typeVariables[4]; |
| 724 DartType X = I.typeVariables[5]; | 732 ResolutionDartType X = I.typeVariables[5]; |
| 725 | 733 |
| 726 checkLub(DartType a, DartType b, DartType expectedLub) { | 734 checkLub(ResolutionDartType a, ResolutionDartType b, |
| 727 DartType lub = env.computeLeastUpperBound(a, b); | 735 ResolutionDartType expectedLub) { |
| 736 ResolutionDartType lub = env.computeLeastUpperBound(a, b); |
| 728 Expect.equals(expectedLub, lub, | 737 Expect.equals(expectedLub, lub, |
| 729 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); | 738 'Unexpected lub($a,$b) = $lub, expected $expectedLub'); |
| 730 } | 739 } |
| 731 | 740 |
| 732 checkLub(Object_, Object_, Object_); | 741 checkLub(Object_, Object_, Object_); |
| 733 checkLub(Object_, A, Object_); | 742 checkLub(Object_, A, Object_); |
| 734 checkLub(Object_, B, Object_); | 743 checkLub(Object_, B, Object_); |
| 735 checkLub(Object_, C, Object_); | 744 checkLub(Object_, C, Object_); |
| 736 checkLub(Object_, S, Object_); | 745 checkLub(Object_, S, Object_); |
| 737 checkLub(Object_, T, Object_); | 746 checkLub(Object_, T, Object_); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 checkLub(X, B, B); | 842 checkLub(X, B, B); |
| 834 checkLub(X, C, B); | 843 checkLub(X, C, B); |
| 835 checkLub(X, S, Object_); | 844 checkLub(X, S, Object_); |
| 836 checkLub(X, T, T); | 845 checkLub(X, T, T); |
| 837 checkLub(X, U, B); | 846 checkLub(X, U, B); |
| 838 checkLub(X, V, T); | 847 checkLub(X, V, T); |
| 839 checkLub(X, W, T); | 848 checkLub(X, W, T); |
| 840 checkLub(X, X, X); | 849 checkLub(X, X, X); |
| 841 })); | 850 })); |
| 842 } | 851 } |
| OLD | NEW |