| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // VMOptions=--enable_type_checks |
| 4 | 5 |
| 5 // Test of parameterized factory methods. | 6 // Test of parameterized factory methods. |
| 6 | 7 |
| 7 class Foo<F extends num> { | 8 class Foo<T extends num> { |
| 8 Foo(); | 9 Foo(); |
| 9 | 10 |
| 10 // F is not assignable to num. | 11 // F is not assignable to num. |
| 11 factory IFoo<F extends String>.bad() { return null; } /// 00: compile-time err
or | 12 factory IFoo<F extends String>.bad() { return null; } /// 00: static type erro
r |
| 12 | 13 |
| 13 factory IFoo<F extends num>.good() { return null; } | 14 factory IFoo<F extends num>.good() { return null; } |
| 14 | 15 |
| 15 // The bound of F is Object which is assignable to num. | 16 // The bound of F is Object which is assignable to num. |
| 16 factory IFoo<F>.ish() { return null; } | 17 factory IFoo<F>.ish() { return null; } |
| 17 } | 18 } |
| 18 | 19 |
| 19 interface IFoo<X extends num> factory Foo { | 20 interface IFoo<X extends num> factory Foo<T extends num> { |
| 20 } | 21 } |
| 21 | 22 |
| 22 class FBound<F extends FBound<F>> {} | |
| 23 | |
| 24 class Bar extends FBound<Bar> {} | |
| 25 | |
| 26 class SubBar extends Bar {} | |
| 27 | |
| 28 // String is not assignable to num. | 23 // String is not assignable to num. |
| 29 class Baz extends Foo<String> {} /// 01: compile-time error | 24 class Baz extends Foo<String> {} /// 01: compile-time error |
| 30 | 25 |
| 31 class Biz extends Foo<int> {} | 26 class Biz extends Foo<int> {} |
| 32 | 27 |
| 33 Foo<int> fi; | 28 Foo<int> fi; |
| 34 | 29 |
| 35 // String is not assignable to num. | 30 // String is not assignable to num. |
| 36 Foo<String> fs; /// 02: static type error | 31 Foo<String> fs; /// 02: compile-time error |
| 37 | |
| 38 FBound<SubBar> fb; /// 03: static type error | |
| 39 | 32 |
| 40 class Box<T> { | 33 class Box<T> { |
| 41 | 34 |
| 42 // Box.T is not assignable to num. | 35 // Box.T is not assignable to num. |
| 43 Foo<T> t; /// 04: static type error | 36 Foo<T> t; /// 03: static type error |
| 44 | 37 |
| 45 makeFoo() { | 38 makeFoo() { |
| 46 // Box.T is not assignable to num. | 39 // Box.T is not assignable to num. |
| 47 return new Foo<T>(); /// 05: compile-time error | 40 return new Foo<T>(); /// 04: static type error |
| 48 } | 41 } |
| 49 } | 42 } |
| 50 | 43 |
| 51 class TypeVariableBoundsTest { | 44 class TypeVariableBoundsTest { |
| 52 static testMain() { | 45 static testMain() { |
| 53 // String is not assignable to num. | 46 // String is not assignable to num. |
| 54 var v1 = new Foo<String>(); /// 06: compile-time error | 47 var v1 = new Foo<String>(); /// 05: compile-time error |
| 55 | 48 |
| 56 // String is not assignable to num. | 49 // String is not assignable to num. |
| 57 Foo<String> v2 = null; /// 07: static type error | 50 Foo<String> v2 = null; /// 06: compile-time error |
| 58 } | 51 } |
| 59 } | 52 } |
| 60 | 53 |
| 61 main() { | 54 main() { |
| 62 TypeVariableBoundsTest.testMain(); | 55 TypeVariableBoundsTest.testMain(); |
| 63 } | 56 } |
| OLD | NEW |