| 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 |
| 11 | 11 |
| 12 typedef int functype({x, y, z}); | 12 typedef int functype({x, y, z}); |
| 13 | 13 |
| 14 int topF({x = 3, y : 5, z}) => x * y * (z ?? 2); | 14 int topF({x = 3, y: 5, z}) => x * y * (z ?? 2); |
| 15 | 15 |
| 16 class A { | 16 class A { |
| 17 int x; | 17 int x; |
| 18 int y; | 18 int y; |
| 19 int z; | 19 int z; |
| 20 A({this.x = 3, this.y : 5, z }) : z = z ?? 2; | 20 A({this.x = 3, this.y: 5, z}) : z = z ?? 2; |
| 21 A.redirect({x = 3, y : 5, z}) : this(x: x, y: y, z: z); | 21 A.redirect({x = 3, y: 5, z}) : this(x: x, y: y, z: z); |
| 22 factory A.factory({x = 3, y : 5, z}) => new A(x: x, y: y, z: z ?? 2); | 22 factory A.factory({x = 3, y: 5, z}) => new A(x: x, y: y, z: z ?? 2); |
| 23 factory A.redirectFactory({x, y, z}) = A; | 23 factory A.redirectFactory({x, y, z}) = A; |
| 24 | 24 |
| 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 | 35 // Reference the type, or dart2js won't see that the declaration is invalid |
| 36 F1 _ = null; // //# 01: continued | 36 F1 _ = null; // //# 01: continued |
| 37 | 37 |
| 38 var a = new A(); | 38 var a = new A(); |
| 39 | 39 |
| 40 int local({x = 3, y : 5, z}) => x * y * (z ?? 2); | 40 int local({x = 3, y: 5, z}) => x * y * (z ?? 2); |
| 41 var expr = ({x = 3, y : 5, z}) => x * y * (z ?? 2); | 41 var expr = ({x = 3, y: 5, z}) => x * y * (z ?? 2); |
| 42 var tearOff = a.instanceF; | 42 var tearOff = a.instanceF; |
| 43 | 43 |
| 44 test(function) { | 44 test(function) { |
| 45 Expect.equals(30, function()); | 45 Expect.equals(30, function()); |
| 46 Expect.equals(70, function(x: 7)); | 46 Expect.equals(70, function(x: 7)); |
| 47 Expect.equals(42, function(y: 7)); | 47 Expect.equals(42, function(y: 7)); |
| 48 Expect.equals(28, function(x: 7, y: 2)); | 48 Expect.equals(28, function(x: 7, y: 2)); |
| 49 Expect.equals(15, function(z: 1)); | 49 Expect.equals(15, function(z: 1)); |
| 50 Expect.equals(21, function(y: 7, z: 1)); | 50 Expect.equals(21, function(y: 7, z: 1)); |
| 51 Expect.equals(35, function(x: 7, z: 1)); | 51 Expect.equals(35, function(x: 7, z: 1)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 Expect.equals(30, new A.redirectFactory().value); | 91 Expect.equals(30, new A.redirectFactory().value); |
| 92 Expect.equals(70, new A.redirectFactory(x: 7).value); | 92 Expect.equals(70, new A.redirectFactory(x: 7).value); |
| 93 Expect.equals(42, new A.redirectFactory(y: 7).value); | 93 Expect.equals(42, new A.redirectFactory(y: 7).value); |
| 94 Expect.equals(28, new A.redirectFactory(x: 7, y: 2).value); | 94 Expect.equals(28, new A.redirectFactory(x: 7, y: 2).value); |
| 95 Expect.equals(15, new A.redirectFactory(z: 1).value); | 95 Expect.equals(15, new A.redirectFactory(z: 1).value); |
| 96 Expect.equals(21, new A.redirectFactory(y: 7, z: 1).value); | 96 Expect.equals(21, new A.redirectFactory(y: 7, z: 1).value); |
| 97 Expect.equals(35, new A.redirectFactory(x: 7, z: 1).value); | 97 Expect.equals(35, new A.redirectFactory(x: 7, z: 1).value); |
| 98 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); |
| 99 } | 99 } |
| OLD | NEW |