| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:math' as math; | 5 import 'dart:math' as math; |
| 6 import 'dart:math' show min; // <-- generic: <T extends num>(T, T) -> T | 6 import 'dart:math' show min; // <-- generic: <T extends num>(T, T) -> T |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 | 8 |
| 9 class C { | 9 class C { |
| 10 /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => min(x, y); | 10 T m<T extends num>(T x, T y) => min(x, y); |
| 11 int m2(int x, int y) => min(x, y); | 11 int m2(int x, int y) => min(x, y); |
| 12 } | 12 } |
| 13 | 13 |
| 14 typedef int Int2Int2Int(int x, int y); | 14 typedef int Int2Int2Int(int x, int y); |
| 15 | 15 |
| 16 void _test(Int2Int2Int f) { | 16 void _test(Int2Int2Int f) { |
| 17 int y = f(123, 456); | 17 int y = f(123, 456); |
| 18 Expect.equals(y, 123); | 18 Expect.equals(y, 123); |
| 19 // `f` doesn't take type args. | 19 // `f` doesn't take type args. |
| 20 Expect.throws(() => (f as dynamic) /*<int>*/(123, 456)); | 20 Expect.throws(() => (f as dynamic)<int>(123, 456)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void _testParam(/*=T*/ minFn/*<T extends num>*/(/*=T*/ x, /*=T*/ y)) { | 23 void _testParam(T minFn<T extends num>(T x, T y)) { |
| 24 _test(minFn); | 24 _test(minFn); |
| 25 } | 25 } |
| 26 | 26 |
| 27 main() { | 27 main() { |
| 28 // Strong mode infers: `min<int>` | 28 // Strong mode infers: `min<int>` |
| 29 // Test simple/prefixed identifiers and property access | 29 // Test simple/prefixed identifiers and property access |
| 30 _test(min); | 30 _test(min); |
| 31 _test(math.min); | 31 _test(math.min); |
| 32 _test(new C().m); | 32 _test(new C().m); |
| 33 | 33 |
| 34 // Test local function, variable, and parameter | 34 // Test local function, variable, and parameter |
| 35 /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => min(x, y); | 35 T m<T extends num>(T x, T y) => min(x, y); |
| 36 _test(m); | 36 _test(m); |
| 37 final f = min; | 37 final f = min; |
| 38 _test(f); | 38 _test(f); |
| 39 _testParam(math.min); | 39 _testParam(math.min); |
| 40 | 40 |
| 41 // A few misc tests for methods | 41 // A few misc tests for methods |
| 42 Expect.equals(123, (new C() as dynamic).m/*<int>*/(123, 456)); | 42 Expect.equals(123, (new C() as dynamic).m<int>(123, 456)); |
| 43 Expect.throws(() => (new C() as dynamic).m2/*<int>*/(123, 456)); | 43 Expect.throws(() => (new C() as dynamic).m2<int>(123, 456)); |
| 44 } | 44 } |
| OLD | NEW |