|
| 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 | +// Tests multiple wildcard function parameters. |
| 6 | + |
| 7 | +// SharedOptions=--enable-experiment=wildcard-variables |
| 8 | + |
| 9 | +import 'package:expect/expect.dart'; |
| 10 | + |
| 11 | +class Constructor { |
| 12 | + final _; |
| 13 | + |
| 14 | + // TODO(kallentu): Update this once the behaviour of super._ is finalized. |
| 15 | + // https://github.com/dart-lang/language/issues/3792 |
| 16 | + Constructor.multiple(_, this._, void _()) {} |
| 17 | + Constructor.parameter(_, _, this._) {} |
| 18 | + Constructor.functionType(this._, void _(), void _()) {} |
| 19 | +} |
| 20 | + |
| 21 | +bool topLevelFunction(int _, int _) => true; |
| 22 | +bool topLevelFunction2(_, _) => true; |
| 23 | +bool topLevelFunction_functionType(void _(), void _()) => true; |
| 24 | + |
| 25 | +class InstanceMethod { |
| 26 | + bool instanceMethod(int _, int _) => true; |
| 27 | + bool instanceMethod2(_, _) => true; |
| 28 | + bool instanceMethod_functionType(void _(), void _()) => true; |
| 29 | + |
| 30 | + // User-defined operators |
| 31 | + int operator +(int _) => 42; |
| 32 | + void operator []=(int _, _) {} |
| 33 | + |
| 34 | + // Inherited `Object` methods |
| 35 | + dynamic noSuchMethod(Invocation _) => true; |
| 36 | + bool operator ==(Object _) => true; |
| 37 | +} |
| 38 | + |
| 39 | +abstract class AbstractMethod { |
| 40 | + bool abstractMethod(int _, int _); |
| 41 | + bool abstractMethod2(_, _); |
| 42 | + bool abstractMethod_functionType(void _(), void _()); |
| 43 | +} |
| 44 | + |
| 45 | +class AbstractMethodSubclass extends AbstractMethod { |
| 46 | + bool abstractMethod(int _, int _) => true; |
| 47 | + bool abstractMethod2(_, _) => true; |
| 48 | + bool abstractMethod_functionType(void _(), void _()) => true; |
| 49 | +} |
| 50 | + |
| 51 | +class Setter { |
| 52 | + int _x; |
| 53 | + Setter(this._x); |
| 54 | + |
| 55 | + int get x => _x; |
| 56 | + set x(int _) => _x = 2; |
| 57 | +} |
| 58 | + |
| 59 | +class StaticMethod { |
| 60 | + static int staticMethod(int _, int _) => 2; |
| 61 | + static int staticMethod2(_, _) => 2; |
| 62 | + static int staticMethod_functionType(void _(), void _()) => 2; |
| 63 | + static int staticMethod_functionTypeNested( |
| 64 | + void _(_, _), void _(int _, int _)) => |
| 65 | + 2; |
| 66 | + static int staticMethod_functionTypeNew( |
| 67 | + void Function(int _, int _) _, void Function(int _, int _) _) => |
| 68 | + 2; |
| 69 | + static int staticMethod_functionTypeGeneric( |
| 70 | + void Function<_, _>(int _, int _) _, void _<_>(_, _)) => |
| 71 | + 2; |
| 72 | +} |
| 73 | + |
| 74 | +void main() { |
| 75 | + // Function expression |
| 76 | + var list = [true]; |
| 77 | + list.where( |
| 78 | + (_, [_]) => true, |
| 79 | + ); |
| 80 | + |
| 81 | + // Abstract methods |
| 82 | + var abstractMethod = AbstractMethodSubclass(); |
| 83 | + abstractMethod.abstractMethod(1, 2); |
| 84 | + abstractMethod.abstractMethod2(1, 2); |
| 85 | + abstractMethod.abstractMethod_functionType(() {}, () {}); |
| 86 | + |
| 87 | + // Static methods |
| 88 | + StaticMethod.staticMethod(1, 2); |
| 89 | + StaticMethod.staticMethod2(1, 2); |
| 90 | + StaticMethod.staticMethod_functionType(() {}, () {}); |
| 91 | + StaticMethod.staticMethod_functionTypeNested((e, x) {}, (e, x) {}); |
| 92 | + StaticMethod.staticMethod_functionTypeNew((e, x) {}, (e, x) {}); |
| 93 | + StaticMethod.staticMethod_functionTypeNested((_, _) {}, (_, _) {}); |
| 94 | + StaticMethod.staticMethod_functionTypeNew((_, _) {}, (_, _) {}); |
| 95 | + |
| 96 | + // Top level functions |
| 97 | + topLevelFunction(1, 2); |
| 98 | + topLevelFunction2(1, 2); |
| 99 | + topLevelFunction_functionType(() {}, () {}); |
| 100 | + |
| 101 | + // Instance methods |
| 102 | + var instanceMethod = InstanceMethod(); |
| 103 | + instanceMethod.instanceMethod(1, 2); |
| 104 | + instanceMethod.instanceMethod2(1, 2); |
| 105 | + instanceMethod.instanceMethod_functionType(() {}, () {}); |
| 106 | + Expect.equals(42, instanceMethod + 2); |
| 107 | + instanceMethod[1] = 2; |
| 108 | + Expect.isTrue(instanceMethod == 2); |
| 109 | + Expect.isTrue((instanceMethod as dynamic).noMethod()); |
| 110 | + |
| 111 | + // Constructor |
| 112 | + Constructor.multiple(1, 2, () {}); |
| 113 | + Constructor.parameter(1, 2, 3); |
| 114 | + Constructor.functionType(() {}, () {}, () {}); |
| 115 | + |
| 116 | + // Setter |
| 117 | + var setter = Setter(1); |
| 118 | + setter.x = 2; |
| 119 | +} |
0 commit comments