| 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() { | |
| 20 try { | |
| 21 var s = 'string'; | |
| 22 int i = s; | |
| 23 } catch(e) { | |
| 24 return true; | |
| 25 } | |
| 26 return false; | |
| 27 } | |
| 28 | |
| 29 main() { | 19 main() { |
| 30 ClassMirror superDecl = reflectClass(Super); | 20 ClassMirror superDecl = reflectClass(Super); |
| 31 ClassMirror superOfInt = reflectClass(Fixed).superclass; | 21 ClassMirror superOfInt = reflectClass(Fixed).superclass; |
| 32 ClassMirror genericDecl = reflectClass(Generic); /// 02: continued | 22 ClassMirror genericDecl = reflectClass(Generic); /// 02: continued |
| 33 ClassMirror superOfR = genericDecl.superclass; /// 02: continued | 23 ClassMirror superOfR = genericDecl.superclass; /// 02: continued |
| 34 ClassMirror genericOfDouble = reflect(new Generic<double>()).type; /// 02: co
ntinued | 24 ClassMirror genericOfDouble = reflect(new Generic<double>()).type; /// 02: co
ntinued |
| 35 ClassMirror superOfDouble = genericOfDouble.superclass; /// 02: continued | 25 ClassMirror superOfDouble = genericOfDouble.superclass; /// 02: continued |
| 36 | 26 ClassMirror genericOfBool = reflect(new Generic<bool>()).type; /// 02: static
type warning, dynamic type error |
| 37 try { | 27 ClassMirror superOfBool = genericOfBool.superclass; /// 02: continued |
| 38 ClassMirror genericOfBool = reflect(new Generic<bool>()).type; /// 02: stat
ic type warning | |
| 39 ClassMirror superOfBool = genericOfBool.superclass; /// 02: continued | |
| 40 Expect.isFalse(genericOfBool.isOriginalDeclaration); /// 02: continued | |
| 41 Expect.isFalse(superOfBool.isOriginalDeclaration); /// 02: continued | |
| 42 typeParameters(genericOfBool, [#R]); /// 02: continued | |
| 43 typeParameters(superOfBool, [#T]); /// 02: continued | |
| 44 typeArguments(genericOfBool, [reflectClass(bool)]); /// 02: continued | |
| 45 typeArguments(superOfBool, [reflectClass(bool)]); /// 02: continued | |
| 46 Expect.isFalse(inCheckedMode()); /// 02: continued | |
| 47 } on TypeError catch(e) { | |
| 48 Expect.isTrue(inCheckedMode()); | |
| 49 } | |
| 50 | |
| 51 ClassMirror superOfString = reflectClass(Malbounded).superclass; /// 01: cont
inued | 28 ClassMirror superOfString = reflectClass(Malbounded).superclass; /// 01: cont
inued |
| 52 | 29 |
| 53 Expect.isTrue(superDecl.isOriginalDeclaration); | 30 Expect.isTrue(superDecl.isOriginalDeclaration); |
| 54 Expect.isFalse(superOfInt.isOriginalDeclaration); | 31 Expect.isFalse(superOfInt.isOriginalDeclaration); |
| 55 Expect.isTrue(genericDecl.isOriginalDeclaration); /// 02: continued | 32 Expect.isTrue(genericDecl.isOriginalDeclaration); /// 02: continued |
| 56 Expect.isFalse(superOfR.isOriginalDeclaration); /// 02: continued | 33 Expect.isFalse(superOfR.isOriginalDeclaration); /// 02: continued |
| 57 Expect.isFalse(genericOfDouble.isOriginalDeclaration); /// 02: continued | 34 Expect.isFalse(genericOfDouble.isOriginalDeclaration); /// 02: continued |
| 58 Expect.isFalse(superOfDouble.isOriginalDeclaration); /// 02: continued | 35 Expect.isFalse(superOfDouble.isOriginalDeclaration); /// 02: continued |
| 59 | 36 Expect.isFalse(genericOfBool.isOriginalDeclaration); /// 02: continued |
| 37 Expect.isFalse(superOfBool.isOriginalDeclaration); /// 02: continued |
| 60 Expect.isFalse(superOfString.isOriginalDeclaration); /// 01: continued | 38 Expect.isFalse(superOfString.isOriginalDeclaration); /// 01: continued |
| 61 | 39 |
| 62 TypeVariableMirror tFromSuper = superDecl.typeVariables.single; | 40 TypeVariableMirror tFromSuper = superDecl.typeVariables.single; |
| 63 TypeVariableMirror rFromGeneric = genericDecl.typeVariables.single; /// 02: c
ontinued | 41 TypeVariableMirror rFromGeneric = genericDecl.typeVariables.single; /// 02: c
ontinued |
| 64 | 42 |
| 65 Expect.equals(reflectClass(num), tFromSuper.upperBound); | 43 Expect.equals(reflectClass(num), tFromSuper.upperBound); |
| 66 Expect.equals(reflectClass(Object), rFromGeneric.upperBound); /// 02: continu
ed | 44 Expect.equals(reflectClass(Object), rFromGeneric.upperBound); /// 02: continu
ed |
| 67 | 45 |
| 68 typeParameters(superDecl, [#T]); | 46 typeParameters(superDecl, [#T]); |
| 69 typeParameters(superOfInt, [#T]); | 47 typeParameters(superOfInt, [#T]); |
| 70 typeParameters(genericDecl, [#R]); /// 02: continued | 48 typeParameters(genericDecl, [#R]); /// 02: continued |
| 71 typeParameters(superOfR, [#T]); /// 02: continued | 49 typeParameters(superOfR, [#T]); /// 02: continued |
| 72 typeParameters(genericOfDouble, [#R]); /// 02: continued | 50 typeParameters(genericOfDouble, [#R]); /// 02: continued |
| 73 typeParameters(superOfDouble, [#T]); /// 02: continued | 51 typeParameters(superOfDouble, [#T]); /// 02: continued |
| 52 typeParameters(genericOfBool, [#R]); /// 02: continued |
| 53 typeParameters(superOfBool, [#T]); /// 02: continued |
| 74 typeParameters(superOfString, [#T]); /// 01: continued | 54 typeParameters(superOfString, [#T]); /// 01: continued |
| 75 | 55 |
| 76 typeArguments(superDecl, []); | 56 typeArguments(superDecl, []); |
| 77 typeArguments(superOfInt, [reflectClass(int)]); | 57 typeArguments(superOfInt, [reflectClass(int)]); |
| 78 typeArguments(genericDecl, []); /// 02: continued | 58 typeArguments(genericDecl, []); /// 02: continued |
| 79 typeArguments(superOfR, [rFromGeneric]); /// 02: continued | 59 typeArguments(superOfR, [rFromGeneric]); /// 02: continued |
| 80 typeArguments(genericOfDouble, [reflectClass(double)]); /// 02: continued | 60 typeArguments(genericOfDouble, [reflectClass(double)]); /// 02: continued |
| 81 typeArguments(superOfDouble, [reflectClass(double)]); /// 02: continued | 61 typeArguments(superOfDouble, [reflectClass(double)]); /// 02: continued |
| 62 typeArguments(genericOfBool, [reflectClass(bool)]); /// 02: continued |
| 63 typeArguments(superOfBool, [reflectClass(bool)]); /// 02: continued |
| 82 typeArguments(superOfString, [reflectClass(String)]); /// 01: continued | 64 typeArguments(superOfString, [reflectClass(String)]); /// 01: continued |
| 83 } | 65 } |
| OLD | NEW |