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 // Check that both `=` and `:` are allowed for named parameters. | 5 // Check that both `=` and `:` are allowed for named parameters. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 // Default values are not allowed on typedefs. | 9 // Default values are not allowed on typedefs. |
10 typedef int F1({x = 3, y}); /// 01: compile-time error | 10 typedef int F1({x = 3, y}); /// 01: compile-time error |
(...skipping 14 matching lines...) Expand all Loading... |
25 // Default values are not allowed on redirecting factory constructors. | 25 // Default values are not allowed on redirecting factory constructors. |
26 factory A.badRedirectFactory({x = 3, y}) = A; /// 02: compile-time error | 26 factory A.badRedirectFactory({x = 3, y}) = A; /// 02: compile-time error |
27 | 27 |
28 int get value => x * y * z; | 28 int get value => x * y * z; |
29 | 29 |
30 static int staticF({x = 3, y : 5, z}) => x * y * (z ?? 2); | 30 static int staticF({x = 3, y : 5, z}) => x * y * (z ?? 2); |
31 int instanceF({x = 3, y : 5, z}) => x * y * (z ?? 2); | 31 int instanceF({x = 3, y : 5, z}) => x * y * (z ?? 2); |
32 } | 32 } |
33 | 33 |
34 main() { | 34 main() { |
| 35 // Reference the type, or dart2js won't see that the declaration is invalid |
| 36 F1 _ = null; /// 01: continued |
| 37 |
35 var a = new A(); | 38 var a = new A(); |
36 | 39 |
37 int local({x = 3, y : 5, z}) => x * y * (z ?? 2); | 40 int local({x = 3, y : 5, z}) => x * y * (z ?? 2); |
38 var expr = ({x = 3, y : 5, z}) => x * y * (z ?? 2); | 41 var expr = ({x = 3, y : 5, z}) => x * y * (z ?? 2); |
39 var tearOff = a.instanceF; | 42 var tearOff = a.instanceF; |
40 | 43 |
41 test(function) { | 44 test(function) { |
42 Expect.equals(30, function()); | 45 Expect.equals(30, function()); |
43 Expect.equals(70, function(x: 7)); | 46 Expect.equals(70, function(x: 7)); |
44 Expect.equals(42, function(y: 7)); | 47 Expect.equals(42, function(y: 7)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 90 |
88 Expect.equals(30, new A.redirectFactory().value); | 91 Expect.equals(30, new A.redirectFactory().value); |
89 Expect.equals(70, new A.redirectFactory(x: 7).value); | 92 Expect.equals(70, new A.redirectFactory(x: 7).value); |
90 Expect.equals(42, new A.redirectFactory(y: 7).value); | 93 Expect.equals(42, new A.redirectFactory(y: 7).value); |
91 Expect.equals(28, new A.redirectFactory(x: 7, y: 2).value); | 94 Expect.equals(28, new A.redirectFactory(x: 7, y: 2).value); |
92 Expect.equals(15, new A.redirectFactory(z: 1).value); | 95 Expect.equals(15, new A.redirectFactory(z: 1).value); |
93 Expect.equals(21, new A.redirectFactory(y: 7, z: 1).value); | 96 Expect.equals(21, new A.redirectFactory(y: 7, z: 1).value); |
94 Expect.equals(35, new A.redirectFactory(x: 7, z: 1).value); | 97 Expect.equals(35, new A.redirectFactory(x: 7, z: 1).value); |
95 Expect.equals(14, new A.redirectFactory(x: 7, y: 2, z: 1).value); | 98 Expect.equals(14, new A.redirectFactory(x: 7, y: 2, z: 1).value); |
96 } | 99 } |
OLD | NEW |