OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /*@testedFeatures=inference*/ | 5 /*@testedFeatures=inference*/ |
6 library test; | 6 library test; |
7 | 7 |
8 import 'dart:math'; | 8 import 'dart:math'; |
9 | 9 |
10 void printInt(int x) => print(/*@promotedType=none*/ x); | 10 void printInt(int x) => print(/*@promotedType=none*/ x); |
11 void printDouble(double x) => print(/*@promotedType=none*/ x); | 11 void printDouble(double x) => print(/*@promotedType=none*/ x); |
12 | 12 |
13 num myMax(num x, num y) => | 13 num myMax(num x, num y) => |
14 max(/*@promotedType=none*/ x, /*@promotedType=none*/ y); | 14 /*@typeArgs=num*/ max(/*@promotedType=none*/ x, /*@promotedType=none*/ y); |
15 | 15 |
16 f() { | 16 f() { |
17 // Okay if static types match. | 17 // Okay if static types match. |
18 printInt(max(1, 2)); | 18 printInt(/*@typeArgs=int*/ max(1, 2)); |
19 printInt(min(1, 2)); | 19 printInt(/*@typeArgs=int*/ min(1, 2)); |
20 printDouble(max(1.0, 2.0)); | 20 printDouble(/*@typeArgs=double*/ max(1.0, 2.0)); |
21 printDouble(min(1.0, 2.0)); | 21 printDouble(/*@typeArgs=double*/ min(1.0, 2.0)); |
22 | 22 |
23 // No help for user-defined functions from num->num->num. | 23 // No help for user-defined functions from num->num->num. |
24 printInt(/*info:DOWN_CAST_IMPLICIT*/ myMax(1, 2)); | 24 printInt(/*info:DOWN_CAST_IMPLICIT*/ myMax(1, 2)); |
25 printInt(myMax(1, 2) as int); | 25 printInt(myMax(1, 2) as int); |
26 | 26 |
27 // Mixing int and double means return type is num. | 27 // Mixing int and double means return type is num. |
28 printInt(max(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 2.0)); | 28 printInt( |
29 printInt(min(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 2.0)); | 29 /*@typeArgs=int*/ max(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 2.0)); |
30 printDouble(max(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 1, 2.0)); | 30 printInt( |
31 printDouble(min(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 1, 2.0)); | 31 /*@typeArgs=int*/ min(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 2.0)); |
| 32 printDouble( |
| 33 /*@typeArgs=double*/ max(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 1, 2.0)); |
| 34 printDouble( |
| 35 /*@typeArgs=double*/ min(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 1, 2.0)); |
32 | 36 |
33 // Types other than int and double are not accepted. | 37 // Types other than int and double are not accepted. |
34 printInt(min( | 38 printInt(/*@typeArgs=int*/ min( |
35 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ "hi", | 39 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ "hi", |
36 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ "there")); | 40 /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ "there")); |
37 } | 41 } |
38 | 42 |
39 main() {} | 43 main() {} |
OLD | NEW |