|
| 1 | +// Copyright (c) 2024, 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 | +// Unnamed optional parameters, which are not initializing or super parameters, |
| 6 | +// that have no default values, have no errors. |
| 7 | + |
| 8 | +// SharedOptions=--enable-experiment=wildcard-variables |
| 9 | + |
| 10 | +import 'package:expect/expect.dart'; |
| 11 | + |
| 12 | +class C { |
| 13 | + C([int _]) {} |
| 14 | + C.otherParams([int _, bool x = false, bool _ = true]) {} |
| 15 | + C.otherParams2([int _ = 1, bool x = false, bool _]) {} |
| 16 | + |
| 17 | + int foo([int _]) => 1; |
| 18 | + int foo2([bool x = false, bool _, int _]) => 1; |
| 19 | + int foo3([bool? x, bool _ = false, int _]) => 1; |
| 20 | + int foo4([int _, bool? x, bool _ = false]) => 1; |
| 21 | + |
| 22 | + static int fn([int _]) => 1; |
| 23 | + static int fn2([bool x = false, bool _, int _]) => 1; |
| 24 | + static int fn3([bool? x, bool _ = false, int _]) => 1; |
| 25 | + static int fn4([int _, bool? x, bool _ = false]) => 1; |
| 26 | +} |
| 27 | + |
| 28 | +int _([bool _]) => 1; |
| 29 | +int topFoo2([bool x = false, bool _, int _]) => 1; |
| 30 | +int topFoo3([bool? x, bool _ = false, int _]) => 1; |
| 31 | +int topFoo4([int _, bool? x, bool _ = false]) => 1; |
| 32 | + |
| 33 | +void main() { |
| 34 | + Expect.equals(1, _()); |
| 35 | + Expect.equals(1, topFoo2()); |
| 36 | + Expect.equals(1, topFoo3()); |
| 37 | + Expect.equals(1, topFoo4()); |
| 38 | + |
| 39 | + int foo([int _]) => 1; |
| 40 | + int foo2([bool x = false, bool _, int _]) => 1; |
| 41 | + int foo3([bool? x, bool _ = false, int _]) => 1; |
| 42 | + int foo4([int _, bool? x, bool _ = false]) => 1; |
| 43 | + Expect.equals(1, foo()); |
| 44 | + Expect.equals(1, foo2()); |
| 45 | + Expect.equals(1, foo3()); |
| 46 | + Expect.equals(1, foo4()); |
| 47 | + |
| 48 | + var c = C(); |
| 49 | + Expect.equals(1, c.foo()); |
| 50 | + Expect.equals(1, c.foo2()); |
| 51 | + Expect.equals(1, c.foo3()); |
| 52 | + Expect.equals(1, c.foo4()); |
| 53 | + |
| 54 | + Expect.equals(1, C.otherParams().foo()); |
| 55 | + Expect.equals(1, C.otherParams2().foo()); |
| 56 | + |
| 57 | + Expect.equals(1, C.fn()); |
| 58 | + Expect.equals(1, C.fn2()); |
| 59 | + Expect.equals(1, C.fn3()); |
| 60 | + Expect.equals(1, C.fn4()); |
| 61 | +} |
0 commit comments