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