| 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 test.generic_bounded; | 5 library test.generic_bounded; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 | 10 |
| 11 import 'generics_helper.dart'; | 11 import 'generics_helper.dart'; |
| 12 | 12 |
| 13 class Super<T extends num> {} | 13 class Super<T extends num> {} |
| 14 | 14 |
| 15 class Fixed extends Super<int> {} | 15 class Fixed extends Super<int> {} |
| 16 class Generic<R> extends Super<R> {} // //# 02: static type warning | 16 class Generic<R> extends Super<R> {} // //# 02: static type warning |
| 17 class Malbounded extends Super<String> {} //# 01: static type warning | 17 class Malbounded extends Super<String> {} //# 01: static type warning |
| 18 | 18 |
| 19 bool inCheckedMode() { | 19 bool inCheckedMode() { |
| 20 try { | 20 try { |
| 21 var s = 'string'; | 21 var s = 'string'; |
| 22 int i = s; | 22 int i = s; |
| 23 } catch(e) { | 23 } catch (e) { |
| 24 return true; | 24 return true; |
| 25 } | 25 } |
| 26 return false; | 26 return false; |
| 27 } | 27 } |
| 28 | 28 |
| 29 main() { | 29 main() { |
| 30 ClassMirror superDecl = reflectClass(Super); | 30 ClassMirror superDecl = reflectClass(Super); |
| 31 ClassMirror superOfInt = reflectClass(Fixed).superclass; | 31 ClassMirror superOfInt = reflectClass(Fixed).superclass; |
| 32 ClassMirror genericDecl = reflectClass(Generic); // //# 02: continued | 32 ClassMirror genericDecl = reflectClass(Generic); // //# 02: continued |
| 33 ClassMirror superOfR = genericDecl.superclass; // //# 02: continued | 33 ClassMirror superOfR = genericDecl.superclass; // //# 02: continued |
| 34 ClassMirror genericOfDouble = reflect(new Generic<double>()).type; // //# 02:
continued | 34 ClassMirror genericOfDouble = reflect(new Generic<double>()).type; // //# 02:
continued |
| 35 ClassMirror superOfDouble = genericOfDouble.superclass; // //# 02: continued | 35 ClassMirror superOfDouble = genericOfDouble.superclass; // //# 02: continued |
| 36 | 36 |
| 37 try { | 37 try { |
| 38 ClassMirror genericOfBool = reflect(new Generic<bool>()).type; // //# 02: st
atic type warning | 38 ClassMirror genericOfBool = reflect(new Generic<bool>()).type; // //# 02: st
atic type warning |
| 39 ClassMirror superOfBool = genericOfBool.superclass; // //# 02: continued | 39 ClassMirror superOfBool = genericOfBool.superclass; // //# 02: continued |
| 40 Expect.isFalse(genericOfBool.isOriginalDeclaration); // //# 02: continued | 40 Expect.isFalse(genericOfBool.isOriginalDeclaration); // //# 02: continued |
| 41 Expect.isFalse(superOfBool.isOriginalDeclaration); // //# 02: continued | 41 Expect.isFalse(superOfBool.isOriginalDeclaration); // //# 02: continued |
| 42 typeParameters(genericOfBool, [#R]); // //# 02: continued | 42 typeParameters(genericOfBool, [#R]); // //# 02: continued |
| 43 typeParameters(superOfBool, [#T]); // //# 02: continued | 43 typeParameters(superOfBool, [#T]); // //# 02: continued |
| 44 typeArguments(genericOfBool, [reflectClass(bool)]); // //# 02: continued | 44 typeArguments(genericOfBool, [reflectClass(bool)]); // //# 02: continued |
| 45 typeArguments(superOfBool, [reflectClass(bool)]); // //# 02: continued | 45 typeArguments(superOfBool, [reflectClass(bool)]); // //# 02: continued |
| 46 Expect.isFalse(inCheckedMode()); //# 02: continued | 46 Expect.isFalse(inCheckedMode()); //# 02: continued |
| 47 } on TypeError catch(e) { | 47 } on TypeError catch (e) { |
| 48 Expect.isTrue(inCheckedMode()); | 48 Expect.isTrue(inCheckedMode()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ClassMirror superOfString = reflectClass(Malbounded).superclass; // //# 01: co
ntinued | 51 ClassMirror superOfString = reflectClass(Malbounded).superclass; // //# 01: co
ntinued |
| 52 | 52 |
| 53 Expect.isTrue(superDecl.isOriginalDeclaration); | 53 Expect.isTrue(superDecl.isOriginalDeclaration); |
| 54 Expect.isFalse(superOfInt.isOriginalDeclaration); | 54 Expect.isFalse(superOfInt.isOriginalDeclaration); |
| 55 Expect.isTrue(genericDecl.isOriginalDeclaration); // //# 02: continued | 55 Expect.isTrue(genericDecl.isOriginalDeclaration); // //# 02: continued |
| 56 Expect.isFalse(superOfR.isOriginalDeclaration); // //# 02: continued | 56 Expect.isFalse(superOfR.isOriginalDeclaration); // //# 02: continued |
| 57 Expect.isFalse(genericOfDouble.isOriginalDeclaration); // //# 02: continued | 57 Expect.isFalse(genericOfDouble.isOriginalDeclaration); // //# 02: continued |
| (...skipping 16 matching lines...) Expand all Loading... |
| 74 typeParameters(superOfString, [#T]); // //# 01: continued | 74 typeParameters(superOfString, [#T]); // //# 01: continued |
| 75 | 75 |
| 76 typeArguments(superDecl, []); | 76 typeArguments(superDecl, []); |
| 77 typeArguments(superOfInt, [reflectClass(int)]); | 77 typeArguments(superOfInt, [reflectClass(int)]); |
| 78 typeArguments(genericDecl, []); // //# 02: continued | 78 typeArguments(genericDecl, []); // //# 02: continued |
| 79 typeArguments(superOfR, [rFromGeneric]); // //# 02: continued | 79 typeArguments(superOfR, [rFromGeneric]); // //# 02: continued |
| 80 typeArguments(genericOfDouble, [reflectClass(double)]); // //# 02: continued | 80 typeArguments(genericOfDouble, [reflectClass(double)]); // //# 02: continued |
| 81 typeArguments(superOfDouble, [reflectClass(double)]); // //# 02: continued | 81 typeArguments(superOfDouble, [reflectClass(double)]); // //# 02: continued |
| 82 typeArguments(superOfString, [reflectClass(String)]); // //# 01: continued | 82 typeArguments(superOfString, [reflectClass(String)]); // //# 01: continued |
| 83 } | 83 } |
| OLD | NEW |