This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move sub attributes before the signature
[perl5.git] / t / op / signatures.t
CommitLineData
30d9c59b
Z
1#!perl
2
3BEGIN {
a817e89d 4 chdir 't' if -d 't';
30d9c59b 5 require './test.pl';
1ccc3f31 6 set_up_inc('../lib');
30d9c59b 7}
30d9c59b 8
71986b33
DM
9use warnings;
10use strict;
30d9c59b
Z
11
12our $a = 123;
13our $z;
14
71986b33
DM
15{
16 no warnings "illegalproto";
17 sub t000 ($a) { $a || "z" }
18 is prototype(\&t000), "\$a", "(\$a) interpreted as protoype when not enabled";
19 is &t000(456), 123, "(\$a) not signature when not enabled";
20 is $a, 123;
21}
30d9c59b 22
894f226e
DM
23eval "#line 8 foo\nsub t004 :method (\$a) { }";
24is $@, "Experimental subroutine signatures not enabled at foo line 8\.\n",
25 "error when not enabled";
26
27eval "#line 8 foo\nsub t005 (\$) (\$a) { }";
28is $@, "Experimental subroutine signatures not enabled at foo line 8\.\n",
29 "error when not enabled";
30
31
32
30d9c59b
Z
33no warnings "experimental::signatures";
34use feature "signatures";
35
36sub t001 { $a || "z" }
37is prototype(\&t001), undef;
38is eval("t001()"), 123;
39is eval("t001(456)"), 123;
40is eval("t001(456, 789)"), 123;
41is $a, 123;
42
43sub t002 () { $a || "z" }
44is prototype(\&t002), undef;
45is eval("t002()"), 123;
46is eval("t002(456)"), undef;
ac7609e4 47like $@, qr/\AToo many arguments for subroutine 'main::t002' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 48is eval("t002(456, 789)"), undef;
ac7609e4 49like $@, qr/\AToo many arguments for subroutine 'main::t002' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
50is $a, 123;
51
52sub t003 ( ) { $a || "z" }
53is prototype(\&t003), undef;
54is eval("t003()"), 123;
55is eval("t003(456)"), undef;
ac7609e4 56like $@, qr/\AToo many arguments for subroutine 'main::t003' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 57is eval("t003(456, 789)"), undef;
ac7609e4 58like $@, qr/\AToo many arguments for subroutine 'main::t003' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
59is $a, 123;
60
61sub t006 ($a) { $a || "z" }
62is prototype(\&t006), undef;
63is eval("t006()"), undef;
ac7609e4 64like $@, qr/\AToo few arguments for subroutine 'main::t006' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
65is eval("t006(0)"), "z";
66is eval("t006(456)"), 456;
67is eval("t006(456, 789)"), undef;
ac7609e4 68like $@, qr/\AToo many arguments for subroutine 'main::t006' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 69is eval("t006(456, 789, 987)"), undef;
ac7609e4 70like $@, qr/\AToo many arguments for subroutine 'main::t006' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
71is $a, 123;
72
73sub t007 ($a, $b) { $a.$b }
74is prototype(\&t007), undef;
75is eval("t007()"), undef;
ac7609e4 76like $@, qr/\AToo few arguments for subroutine 'main::t007' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 77is eval("t007(456)"), undef;
ac7609e4 78like $@, qr/\AToo few arguments for subroutine 'main::t007' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
79is eval("t007(456, 789)"), "456789";
80is eval("t007(456, 789, 987)"), undef;
ac7609e4 81like $@, qr/\AToo many arguments for subroutine 'main::t007' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 82is eval("t007(456, 789, 987, 654)"), undef;
ac7609e4 83like $@, qr/\AToo many arguments for subroutine 'main::t007' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
84is $a, 123;
85
86sub t008 ($a, $b, $c) { $a.$b.$c }
87is prototype(\&t008), undef;
88is eval("t008()"), undef;
ac7609e4 89like $@, qr/\AToo few arguments for subroutine 'main::t008' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 90is eval("t008(456)"), undef;
ac7609e4 91like $@, qr/\AToo few arguments for subroutine 'main::t008' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 92is eval("t008(456, 789)"), undef;
ac7609e4 93like $@, qr/\AToo few arguments for subroutine 'main::t008' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
94is eval("t008(456, 789, 987)"), "456789987";
95is eval("t008(456, 789, 987, 654)"), undef;
ac7609e4 96like $@, qr/\AToo many arguments for subroutine 'main::t008' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
97is $a, 123;
98
99sub t009 ($abc, $def) { $abc.$def }
100is prototype(\&t009), undef;
101is eval("t009()"), undef;
ac7609e4 102like $@, qr/\AToo few arguments for subroutine 'main::t009' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 103is eval("t009(456)"), undef;
ac7609e4 104like $@, qr/\AToo few arguments for subroutine 'main::t009' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
105is eval("t009(456, 789)"), "456789";
106is eval("t009(456, 789, 987)"), undef;
ac7609e4 107like $@, qr/\AToo many arguments for subroutine 'main::t009' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 108is eval("t009(456, 789, 987, 654)"), undef;
ac7609e4 109like $@, qr/\AToo many arguments for subroutine 'main::t009' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
110is $a, 123;
111
112sub t010 ($a, $) { $a || "z" }
113is prototype(\&t010), undef;
114is eval("t010()"), undef;
ac7609e4 115like $@, qr/\AToo few arguments for subroutine 'main::t010' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 116is eval("t010(456)"), undef;
ac7609e4 117like $@, qr/\AToo few arguments for subroutine 'main::t010' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
118is eval("t010(0, 789)"), "z";
119is eval("t010(456, 789)"), 456;
120is eval("t010(456, 789, 987)"), undef;
ac7609e4 121like $@, qr/\AToo many arguments for subroutine 'main::t010' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 122is eval("t010(456, 789, 987, 654)"), undef;
ac7609e4 123like $@, qr/\AToo many arguments for subroutine 'main::t010' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
124is $a, 123;
125
126sub t011 ($, $a) { $a || "z" }
127is prototype(\&t011), undef;
128is eval("t011()"), undef;
ac7609e4 129like $@, qr/\AToo few arguments for subroutine 'main::t011' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 130is eval("t011(456)"), undef;
ac7609e4 131like $@, qr/\AToo few arguments for subroutine 'main::t011' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
132is eval("t011(456, 0)"), "z";
133is eval("t011(456, 789)"), 789;
134is eval("t011(456, 789, 987)"), undef;
ac7609e4 135like $@, qr/\AToo many arguments for subroutine 'main::t011' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 136is eval("t011(456, 789, 987, 654)"), undef;
ac7609e4 137like $@, qr/\AToo many arguments for subroutine 'main::t011' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
138is $a, 123;
139
140sub t012 ($, $) { $a || "z" }
141is prototype(\&t012), undef;
142is eval("t012()"), undef;
ac7609e4 143like $@, qr/\AToo few arguments for subroutine 'main::t012' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 144is eval("t012(456)"), undef;
ac7609e4 145like $@, qr/\AToo few arguments for subroutine 'main::t012' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
146is eval("t012(0, 789)"), 123;
147is eval("t012(456, 789)"), 123;
148is eval("t012(456, 789, 987)"), undef;
ac7609e4 149like $@, qr/\AToo many arguments for subroutine 'main::t012' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 150is eval("t012(456, 789, 987, 654)"), undef;
ac7609e4 151like $@, qr/\AToo many arguments for subroutine 'main::t012' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
152is $a, 123;
153
154sub t013 ($) { $a || "z" }
155is prototype(\&t013), undef;
156is eval("t013()"), undef;
ac7609e4 157like $@, qr/\AToo few arguments for subroutine 'main::t013' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
158is eval("t013(0)"), 123;
159is eval("t013(456)"), 123;
160is eval("t013(456, 789)"), undef;
ac7609e4 161like $@, qr/\AToo many arguments for subroutine 'main::t013' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 162is eval("t013(456, 789, 987)"), undef;
ac7609e4 163like $@, qr/\AToo many arguments for subroutine 'main::t013' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 164is eval("t013(456, 789, 987, 654)"), undef;
ac7609e4 165like $@, qr/\AToo many arguments for subroutine 'main::t013' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
166is $a, 123;
167
168sub t014 ($a = 222) { $a // "z" }
169is prototype(\&t014), undef;
170is eval("t014()"), 222;
171is eval("t014(0)"), 0;
172is eval("t014(undef)"), "z";
173is eval("t014(456)"), 456;
174is eval("t014(456, 789)"), undef;
ac7609e4 175like $@, qr/\AToo many arguments for subroutine 'main::t014' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 176is eval("t014(456, 789, 987)"), undef;
ac7609e4 177like $@, qr/\AToo many arguments for subroutine 'main::t014' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
178is $a, 123;
179
180sub t015 ($a = undef) { $a // "z" }
181is prototype(\&t015), undef;
182is eval("t015()"), "z";
183is eval("t015(0)"), 0;
184is eval("t015(undef)"), "z";
185is eval("t015(456)"), 456;
186is eval("t015(456, 789)"), undef;
ac7609e4 187like $@, qr/\AToo many arguments for subroutine 'main::t015' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 188is eval("t015(456, 789, 987)"), undef;
ac7609e4 189like $@, qr/\AToo many arguments for subroutine 'main::t015' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
190is $a, 123;
191
192sub t016 ($a = do { $z++; 222 }) { $a // "z" }
193$z = 0;
194is prototype(\&t016), undef;
195is eval("t016()"), 222;
196is $z, 1;
197is eval("t016(0)"), 0;
198is eval("t016(undef)"), "z";
199is eval("t016(456)"), 456;
200is eval("t016(456, 789)"), undef;
ac7609e4 201like $@, qr/\AToo many arguments for subroutine 'main::t016' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 202is eval("t016(456, 789, 987)"), undef;
ac7609e4 203like $@, qr/\AToo many arguments for subroutine 'main::t016' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
204is $z, 1;
205is eval("t016()"), 222;
206is $z, 2;
207is $a, 123;
208
209sub t018 { join("/", @_) }
210sub t017 ($p = t018 222, $a = 333) { $p // "z" }
211is prototype(\&t017), undef;
212is eval("t017()"), "222/333";
213is $a, 333;
214$a = 123;
215is eval("t017(0)"), 0;
216is eval("t017(undef)"), "z";
217is eval("t017(456)"), 456;
218is eval("t017(456, 789)"), undef;
ac7609e4 219like $@, qr/\AToo many arguments for subroutine 'main::t017' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 220is eval("t017(456, 789, 987)"), undef;
ac7609e4 221like $@, qr/\AToo many arguments for subroutine 'main::t017' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
222is $a, 123;
223
224sub t019 ($p = 222, $a = 333) { "$p/$a" }
225is prototype(\&t019), undef;
226is eval("t019()"), "222/333";
227is eval("t019(0)"), "0/333";
228is eval("t019(456)"), "456/333";
229is eval("t019(456, 789)"), "456/789";
230is eval("t019(456, 789, 987)"), undef;
ac7609e4 231like $@, qr/\AToo many arguments for subroutine 'main::t019' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
232is $a, 123;
233
234sub t020 :prototype($) { $_[0]."z" }
235sub t021 ($p = t020 222, $a = 333) { "$p/$a" }
236is prototype(\&t021), undef;
237is eval("t021()"), "222z/333";
238is eval("t021(0)"), "0/333";
239is eval("t021(456)"), "456/333";
240is eval("t021(456, 789)"), "456/789";
241is eval("t021(456, 789, 987)"), undef;
ac7609e4 242like $@, qr/\AToo many arguments for subroutine 'main::t021' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
243is $a, 123;
244
245sub t022 ($p = do { $z += 10; 222 }, $a = do { $z++; 333 }) { "$p/$a" }
246$z = 0;
247is prototype(\&t022), undef;
248is eval("t022()"), "222/333";
249is $z, 11;
250is eval("t022(0)"), "0/333";
251is $z, 12;
252is eval("t022(456)"), "456/333";
253is $z, 13;
254is eval("t022(456, 789)"), "456/789";
255is eval("t022(456, 789, 987)"), undef;
ac7609e4 256like $@, qr/\AToo many arguments for subroutine 'main::t022' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
257is $z, 13;
258is $a, 123;
259
260sub t023 ($a = sub { $_[0]."z" }) { $a->("a")."y" }
261is prototype(\&t023), undef;
262is eval("t023()"), "azy";
263is eval("t023(sub { \"x\".\$_[0].\"x\" })"), "xaxy";
264is eval("t023(sub { \"x\".\$_[0].\"x\" }, 789)"), undef;
ac7609e4 265like $@, qr/\AToo many arguments for subroutine 'main::t023' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
266is $a, 123;
267
268sub t036 ($a = $a."x") { $a."y" }
269is prototype(\&t036), undef;
270is eval("t036()"), "123xy";
271is eval("t036(0)"), "0y";
272is eval("t036(456)"), "456y";
273is eval("t036(456, 789)"), undef;
ac7609e4 274like $@, qr/\AToo many arguments for subroutine 'main::t036' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
275is $a, 123;
276
acf0afbd
Z
277sub t120 ($a = $_) { $a // "z" }
278is prototype(\&t120), undef;
279$_ = "___";
280is eval("t120()"), "___";
281$_ = "___";
282is eval("t120(undef)"), "z";
283$_ = "___";
284is eval("t120(0)"), 0;
285$_ = "___";
286is eval("t120(456)"), 456;
287$_ = "___";
288is eval("t120(456, 789)"), undef;
ac7609e4 289like $@, qr/\AToo many arguments for subroutine 'main::t120' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
290is $a, 123;
291
292sub t121 ($a = caller) { $a // "z" }
293is prototype(\&t121), undef;
294is eval("t121()"), "main";
295is eval("t121(undef)"), "z";
296is eval("t121(0)"), 0;
297is eval("t121(456)"), 456;
298is eval("t121(456, 789)"), undef;
ac7609e4 299like $@, qr/\AToo many arguments for subroutine 'main::t121' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
300is eval("package T121::Z; ::t121()"), "T121::Z";
301is eval("package T121::Z; ::t121(undef)"), "z";
302is eval("package T121::Z; ::t121(0)"), 0;
303is eval("package T121::Z; ::t121(456)"), 456;
304is eval("package T121::Z; ::t121(456, 789)"), undef;
ac7609e4 305like $@, qr/\AToo many arguments for subroutine 'main::t121' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
306is $a, 123;
307
308sub t129 ($a = return 222) { $a."x" }
309is prototype(\&t129), undef;
310is eval("t129()"), "222";
311is eval("t129(0)"), "0x";
312is eval("t129(456)"), "456x";
313is eval("t129(456, 789)"), undef;
ac7609e4 314like $@, qr/\AToo many arguments for subroutine 'main::t129' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
315is $a, 123;
316
317use feature "current_sub";
318sub t122 ($c = 5, $r = $c > 0 ? __SUB__->($c - 1) : "") { $c.$r }
319is prototype(\&t122), undef;
320is eval("t122()"), "543210";
321is eval("t122(0)"), "0";
322is eval("t122(1)"), "10";
323is eval("t122(5)"), "543210";
324is eval("t122(5, 789)"), "5789";
325is eval("t122(5, 789, 987)"), undef;
ac7609e4 326like $@, qr/\AToo many arguments for subroutine 'main::t122' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
327is $a, 123;
328
329sub t123 ($list = wantarray) { $list ? "list" : "scalar" }
330is prototype(\&t123), undef;
331is eval("scalar(t123())"), "scalar";
332is eval("(t123())[0]"), "list";
333is eval("scalar(t123(0))"), "scalar";
334is eval("(t123(0))[0]"), "scalar";
335is eval("scalar(t123(1))"), "list";
336is eval("(t123(1))[0]"), "list";
337is eval("t123(456, 789)"), undef;
ac7609e4 338like $@, qr/\AToo many arguments for subroutine 'main::t123' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
339is $a, 123;
340
341sub t124 ($b = (local $a = $a + 1)) { "$a/$b" }
342is prototype(\&t124), undef;
343is eval("t124()"), "124/124";
344is $a, 123;
345is eval("t124(456)"), "123/456";
346is $a, 123;
347is eval("t124(456, 789)"), undef;
ac7609e4 348like $@, qr/\AToo many arguments for subroutine 'main::t124' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
349is $a, 123;
350
351sub t125 ($c = (our $t125_counter)++) { $c }
352is prototype(\&t125), undef;
353is eval("t125()"), 0;
354is eval("t125()"), 1;
355is eval("t125()"), 2;
356is eval("t125(456)"), 456;
357is eval("t125(789)"), 789;
358is eval("t125()"), 3;
359is eval("t125()"), 4;
360is eval("t125(456, 789)"), undef;
ac7609e4 361like $@, qr/\AToo many arguments for subroutine 'main::t125' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
362is $a, 123;
363
364use feature "state";
365sub t126 ($c = (state $s = $z++)) { $c }
366is prototype(\&t126), undef;
367$z = 222;
368is eval("t126(456)"), 456;
369is $z, 222;
370is eval("t126()"), 222;
371is $z, 223;
372is eval("t126(456)"), 456;
373is $z, 223;
374is eval("t126()"), 222;
375is $z, 223;
376is eval("t126(456, 789)"), undef;
ac7609e4 377like $@, qr/\AToo many arguments for subroutine 'main::t126' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
378is $z, 223;
379is $a, 123;
380
381sub t127 ($c = do { state $s = $z++; $s++ }) { $c }
382is prototype(\&t127), undef;
383$z = 222;
384is eval("t127(456)"), 456;
385is $z, 222;
386is eval("t127()"), 222;
387is $z, 223;
388is eval("t127()"), 223;
389is eval("t127()"), 224;
390is $z, 223;
391is eval("t127(456)"), 456;
392is eval("t127(789)"), 789;
393is eval("t127()"), 225;
394is eval("t127()"), 226;
395is eval("t127(456, 789)"), undef;
ac7609e4 396like $@, qr/\AToo many arguments for subroutine 'main::t127' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
397is $z, 223;
398is $a, 123;
399
30d9c59b
Z
400sub t037 ($a = 222, $b = $a."x") { "$a/$b" }
401is prototype(\&t037), undef;
402is eval("t037()"), "222/222x";
403is eval("t037(0)"), "0/0x";
404is eval("t037(456)"), "456/456x";
405is eval("t037(456, 789)"), "456/789";
406is eval("t037(456, 789, 987)"), undef;
ac7609e4 407like $@, qr/\AToo many arguments for subroutine 'main::t037' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
408is $a, 123;
409
acf0afbd
Z
410sub t128 ($a = 222, $b = ($a = 333)) { "$a/$b" }
411is prototype(\&t128), undef;
412is eval("t128()"), "333/333";
413is eval("t128(0)"), "333/333";
414is eval("t128(456)"), "333/333";
415is eval("t128(456, 789)"), "456/789";
416is eval("t128(456, 789, 987)"), undef;
ac7609e4 417like $@, qr/\AToo many arguments for subroutine 'main::t128' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
418is $a, 123;
419
420sub t130 { join(",", @_).";".scalar(@_) }
421sub t131 ($a = 222, $b = goto &t130) { "$a/$b" }
422is prototype(\&t131), undef;
423is eval("t131()"), ";0";
424is eval("t131(0)"), "0;1";
425is eval("t131(456)"), "456;1";
426is eval("t131(456, 789)"), "456/789";
427is eval("t131(456, 789, 987)"), undef;
ac7609e4 428like $@, qr/\AToo many arguments for subroutine 'main::t131' at \(eval \d+\) line 1\.\n\z/;
acf0afbd
Z
429is $a, 123;
430
30d9c59b 431eval "#line 8 foo\nsub t024 (\$a =) { }";
d3d9da4a
DM
432is $@,
433 qq{Optional parameter lacks default expression at foo line 8, near "=) "\n};
30d9c59b
Z
434
435sub t025 ($ = undef) { $a // "z" }
436is prototype(\&t025), undef;
437is eval("t025()"), 123;
438is eval("t025(0)"), 123;
439is eval("t025(456)"), 123;
440is eval("t025(456, 789)"), undef;
ac7609e4 441like $@, qr/\AToo many arguments for subroutine 'main::t025' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 442is eval("t025(456, 789, 987)"), undef;
ac7609e4 443like $@, qr/\AToo many arguments for subroutine 'main::t025' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 444is eval("t025(456, 789, 987, 654)"), undef;
ac7609e4 445like $@, qr/\AToo many arguments for subroutine 'main::t025' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
446is $a, 123;
447
448sub t026 ($ = 222) { $a // "z" }
449is prototype(\&t026), undef;
450is eval("t026()"), 123;
451is eval("t026(0)"), 123;
452is eval("t026(456)"), 123;
453is eval("t026(456, 789)"), undef;
ac7609e4 454like $@, qr/\AToo many arguments for subroutine 'main::t026' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 455is eval("t026(456, 789, 987)"), undef;
ac7609e4 456like $@, qr/\AToo many arguments for subroutine 'main::t026' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 457is eval("t026(456, 789, 987, 654)"), undef;
ac7609e4 458like $@, qr/\AToo many arguments for subroutine 'main::t026' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
459is $a, 123;
460
461sub t032 ($ = do { $z++; 222 }) { $a // "z" }
462$z = 0;
463is prototype(\&t032), undef;
464is eval("t032()"), 123;
465is $z, 1;
466is eval("t032(0)"), 123;
467is eval("t032(456)"), 123;
468is eval("t032(456, 789)"), undef;
ac7609e4 469like $@, qr/\AToo many arguments for subroutine 'main::t032' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 470is eval("t032(456, 789, 987)"), undef;
ac7609e4 471like $@, qr/\AToo many arguments for subroutine 'main::t032' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 472is eval("t032(456, 789, 987, 654)"), undef;
ac7609e4 473like $@, qr/\AToo many arguments for subroutine 'main::t032' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
474is $z, 1;
475is $a, 123;
476
477sub t027 ($ =) { $a // "z" }
478is prototype(\&t027), undef;
479is eval("t027()"), 123;
480is eval("t027(0)"), 123;
481is eval("t027(456)"), 123;
482is eval("t027(456, 789)"), undef;
ac7609e4 483like $@, qr/\AToo many arguments for subroutine 'main::t027' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 484is eval("t027(456, 789, 987)"), undef;
ac7609e4 485like $@, qr/\AToo many arguments for subroutine 'main::t027' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 486is eval("t027(456, 789, 987, 654)"), undef;
ac7609e4 487like $@, qr/\AToo many arguments for subroutine 'main::t027' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
488is $a, 123;
489
490sub t119 ($ =, $a = 333) { $a // "z" }
491is prototype(\&t119), undef;
492is eval("t119()"), 333;
493is eval("t119(0)"), 333;
494is eval("t119(456)"), 333;
495is eval("t119(456, 789)"), 789;
496is eval("t119(456, 789, 987)"), undef;
ac7609e4 497like $@, qr/\AToo many arguments for subroutine 'main::t119' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 498is eval("t119(456, 789, 987, 654)"), undef;
ac7609e4 499like $@, qr/\AToo many arguments for subroutine 'main::t119' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
500is $a, 123;
501
502sub t028 ($a, $b = 333) { "$a/$b" }
503is prototype(\&t028), undef;
504is eval("t028()"), undef;
ac7609e4 505like $@, qr/\AToo few arguments for subroutine 'main::t028' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
506is eval("t028(0)"), "0/333";
507is eval("t028(456)"), "456/333";
508is eval("t028(456, 789)"), "456/789";
509is eval("t028(456, 789, 987)"), undef;
ac7609e4 510like $@, qr/\AToo many arguments for subroutine 'main::t028' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
511is $a, 123;
512
513sub t045 ($a, $ = 333) { "$a/" }
514is prototype(\&t045), undef;
515is eval("t045()"), undef;
ac7609e4 516like $@, qr/\AToo few arguments for subroutine 'main::t045' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
517is eval("t045(0)"), "0/";
518is eval("t045(456)"), "456/";
519is eval("t045(456, 789)"), "456/";
520is eval("t045(456, 789, 987)"), undef;
ac7609e4 521like $@, qr/\AToo many arguments for subroutine 'main::t045' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
522is $a, 123;
523
524sub t046 ($, $b = 333) { "$a/$b" }
525is prototype(\&t046), undef;
526is eval("t046()"), undef;
ac7609e4 527like $@, qr/\AToo few arguments for subroutine 'main::t046' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
528is eval("t046(0)"), "123/333";
529is eval("t046(456)"), "123/333";
530is eval("t046(456, 789)"), "123/789";
531is eval("t046(456, 789, 987)"), undef;
ac7609e4 532like $@, qr/\AToo many arguments for subroutine 'main::t046' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
533is $a, 123;
534
535sub t047 ($, $ = 333) { "$a/" }
536is prototype(\&t047), undef;
537is eval("t047()"), undef;
ac7609e4 538like $@, qr/\AToo few arguments for subroutine 'main::t047' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
539is eval("t047(0)"), "123/";
540is eval("t047(456)"), "123/";
541is eval("t047(456, 789)"), "123/";
542is eval("t047(456, 789, 987)"), undef;
ac7609e4 543like $@, qr/\AToo many arguments for subroutine 'main::t047' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
544is $a, 123;
545
546sub t029 ($a, $b, $c = 222, $d = 333) { "$a/$b/$c/$d" }
547is prototype(\&t029), undef;
548is eval("t029()"), undef;
ac7609e4 549like $@, qr/\AToo few arguments for subroutine 'main::t029' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 550is eval("t029(0)"), undef;
ac7609e4 551like $@, qr/\AToo few arguments for subroutine 'main::t029' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 552is eval("t029(456)"), undef;
ac7609e4 553like $@, qr/\AToo few arguments for subroutine 'main::t029' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
554is eval("t029(456, 789)"), "456/789/222/333";
555is eval("t029(456, 789, 987)"), "456/789/987/333";
556is eval("t029(456, 789, 987, 654)"), "456/789/987/654";
557is eval("t029(456, 789, 987, 654, 321)"), undef;
ac7609e4 558like $@, qr/\AToo many arguments for subroutine 'main::t029' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 559is eval("t029(456, 789, 987, 654, 321, 111)"), undef;
ac7609e4 560like $@, qr/\AToo many arguments for subroutine 'main::t029' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
561is $a, 123;
562
563sub t038 ($a, $b = $a."x") { "$a/$b" }
564is prototype(\&t038), undef;
565is eval("t038()"), undef;
ac7609e4 566like $@, qr/\AToo few arguments for subroutine 'main::t038' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
567is eval("t038(0)"), "0/0x";
568is eval("t038(456)"), "456/456x";
569is eval("t038(456, 789)"), "456/789";
570is eval("t038(456, 789, 987)"), undef;
ac7609e4 571like $@, qr/\AToo many arguments for subroutine 'main::t038' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
572is $a, 123;
573
574eval "#line 8 foo\nsub t030 (\$a = 222, \$b) { }";
d3d9da4a 575is $@, qq{Mandatory parameter follows optional parameter at foo line 8, near "\$b) "\n};
30d9c59b
Z
576
577eval "#line 8 foo\nsub t031 (\$a = 222, \$b = 333, \$c, \$d) { }";
d3d9da4a
DM
578is $@, <<EOF;
579Mandatory parameter follows optional parameter at foo line 8, near "\$c,"
580Mandatory parameter follows optional parameter at foo line 8, near "\$d) "
581EOF
30d9c59b
Z
582
583sub t034 (@abc) { join("/", @abc).";".scalar(@abc) }
584is prototype(\&t034), undef;
585is eval("t034()"), ";0";
586is eval("t034(0)"), "0;1";
587is eval("t034(456)"), "456;1";
588is eval("t034(456, 789)"), "456/789;2";
589is eval("t034(456, 789, 987)"), "456/789/987;3";
590is eval("t034(456, 789, 987, 654)"), "456/789/987/654;4";
591is eval("t034(456, 789, 987, 654, 321)"), "456/789/987/654/321;5";
592is eval("t034(456, 789, 987, 654, 321, 111)"), "456/789/987/654/321/111;6";
593is $a, 123;
594
863e3089 595eval "#line 8 foo\nsub t136 (\@abc = 222) { }";
bb6b75cd 596is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "222) "\n};
863e3089
Z
597
598eval "#line 8 foo\nsub t137 (\@abc =) { }";
bb6b75cd 599is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "=) "\n};
863e3089 600
30d9c59b
Z
601sub t035 (@) { $a }
602is prototype(\&t035), undef;
603is eval("t035()"), 123;
604is eval("t035(0)"), 123;
605is eval("t035(456)"), 123;
606is eval("t035(456, 789)"), 123;
607is eval("t035(456, 789, 987)"), 123;
608is eval("t035(456, 789, 987, 654)"), 123;
609is eval("t035(456, 789, 987, 654, 321)"), 123;
610is eval("t035(456, 789, 987, 654, 321, 111)"), 123;
611is $a, 123;
612
863e3089 613eval "#line 8 foo\nsub t138 (\@ = 222) { }";
bb6b75cd 614is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "222) "\n};
863e3089
Z
615
616eval "#line 8 foo\nsub t139 (\@ =) { }";
bb6b75cd 617is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "=) "\n};
863e3089 618
30d9c59b
Z
619sub t039 (%abc) { join("/", map { $_."=".$abc{$_} } sort keys %abc) }
620is prototype(\&t039), undef;
621is eval("t039()"), "";
622is eval("t039(0)"), undef;
ac7609e4 623like $@, qr#\AOdd name/value argument for subroutine 'main::t039' at \(eval \d+\) line 1\.\n\z#;
30d9c59b 624is eval("t039(456)"), undef;
ac7609e4 625like $@, qr#\AOdd name/value argument for subroutine 'main::t039' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
626is eval("t039(456, 789)"), "456=789";
627is eval("t039(456, 789, 987)"), undef;
ac7609e4 628like $@, qr#\AOdd name/value argument for subroutine 'main::t039' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
629is eval("t039(456, 789, 987, 654)"), "456=789/987=654";
630is eval("t039(456, 789, 987, 654, 321)"), undef;
ac7609e4 631like $@, qr#\AOdd name/value argument for subroutine 'main::t039' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
632is eval("t039(456, 789, 987, 654, 321, 111)"), "321=111/456=789/987=654";
633is $a, 123;
634
863e3089 635eval "#line 8 foo\nsub t140 (\%abc = 222) { }";
bb6b75cd 636is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "222) "\n};
863e3089
Z
637
638eval "#line 8 foo\nsub t141 (\%abc =) { }";
bb6b75cd 639is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "=) "\n};
863e3089 640
30d9c59b
Z
641sub t040 (%) { $a }
642is prototype(\&t040), undef;
643is eval("t040()"), 123;
644is eval("t040(0)"), undef;
ac7609e4 645like $@, qr#\AOdd name/value argument for subroutine 'main::t040' at \(eval \d+\) line 1\.\n\z#;
30d9c59b 646is eval("t040(456)"), undef;
ac7609e4 647like $@, qr#\AOdd name/value argument for subroutine 'main::t040' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
648is eval("t040(456, 789)"), 123;
649is eval("t040(456, 789, 987)"), undef;
ac7609e4 650like $@, qr#\AOdd name/value argument for subroutine 'main::t040' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
651is eval("t040(456, 789, 987, 654)"), 123;
652is eval("t040(456, 789, 987, 654, 321)"), undef;
ac7609e4 653like $@, qr#\AOdd name/value argument for subroutine 'main::t040' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
654is eval("t040(456, 789, 987, 654, 321, 111)"), 123;
655is $a, 123;
656
863e3089 657eval "#line 8 foo\nsub t142 (\% = 222) { }";
bb6b75cd 658is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "222) "\n};
863e3089
Z
659
660eval "#line 8 foo\nsub t143 (\% =) { }";
bb6b75cd 661is $@, qq{A slurpy parameter may not have a default value at foo line 8, near "=) "\n};
863e3089 662
30d9c59b
Z
663sub t041 ($a, @b) { $a.";".join("/", @b) }
664is prototype(\&t041), undef;
665is eval("t041()"), undef;
ac7609e4 666like $@, qr/\AToo few arguments for subroutine 'main::t041' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
667is eval("t041(0)"), "0;";
668is eval("t041(456)"), "456;";
669is eval("t041(456, 789)"), "456;789";
670is eval("t041(456, 789, 987)"), "456;789/987";
671is eval("t041(456, 789, 987, 654)"), "456;789/987/654";
672is eval("t041(456, 789, 987, 654, 321)"), "456;789/987/654/321";
673is eval("t041(456, 789, 987, 654, 321, 111)"), "456;789/987/654/321/111";
674is $a, 123;
675
676sub t042 ($a, @) { $a.";" }
677is prototype(\&t042), undef;
678is eval("t042()"), undef;
ac7609e4 679like $@, qr/\AToo few arguments for subroutine 'main::t042' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
680is eval("t042(0)"), "0;";
681is eval("t042(456)"), "456;";
682is eval("t042(456, 789)"), "456;";
683is eval("t042(456, 789, 987)"), "456;";
684is eval("t042(456, 789, 987, 654)"), "456;";
685is eval("t042(456, 789, 987, 654, 321)"), "456;";
686is eval("t042(456, 789, 987, 654, 321, 111)"), "456;";
687is $a, 123;
688
689sub t043 ($, @b) { $a.";".join("/", @b) }
690is prototype(\&t043), undef;
691is eval("t043()"), undef;
ac7609e4 692like $@, qr/\AToo few arguments for subroutine 'main::t043' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
693is eval("t043(0)"), "123;";
694is eval("t043(456)"), "123;";
695is eval("t043(456, 789)"), "123;789";
696is eval("t043(456, 789, 987)"), "123;789/987";
697is eval("t043(456, 789, 987, 654)"), "123;789/987/654";
698is eval("t043(456, 789, 987, 654, 321)"), "123;789/987/654/321";
699is eval("t043(456, 789, 987, 654, 321, 111)"), "123;789/987/654/321/111";
700is $a, 123;
701
702sub t044 ($, @) { $a.";" }
703is prototype(\&t044), undef;
704is eval("t044()"), undef;
ac7609e4 705like $@, qr/\AToo few arguments for subroutine 'main::t044' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
706is eval("t044(0)"), "123;";
707is eval("t044(456)"), "123;";
708is eval("t044(456, 789)"), "123;";
709is eval("t044(456, 789, 987)"), "123;";
710is eval("t044(456, 789, 987, 654)"), "123;";
711is eval("t044(456, 789, 987, 654, 321)"), "123;";
712is eval("t044(456, 789, 987, 654, 321, 111)"), "123;";
713is $a, 123;
714
715sub t049 ($a, %b) { $a.";".join("/", map { $_."=".$b{$_} } sort keys %b) }
716is prototype(\&t049), undef;
717is eval("t049()"), undef;
ac7609e4 718like $@, qr/\AToo few arguments for subroutine 'main::t049' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
719is eval("t049(222)"), "222;";
720is eval("t049(222, 456)"), undef;
ac7609e4 721like $@, qr#\AOdd name/value argument for subroutine 'main::t049' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
722is eval("t049(222, 456, 789)"), "222;456=789";
723is eval("t049(222, 456, 789, 987)"), undef;
ac7609e4 724like $@, qr#\AOdd name/value argument for subroutine 'main::t049' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
725is eval("t049(222, 456, 789, 987, 654)"), "222;456=789/987=654";
726is eval("t049(222, 456, 789, 987, 654, 321)"), undef;
ac7609e4 727like $@, qr#\AOdd name/value argument for subroutine 'main::t049' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
728is eval("t049(222, 456, 789, 987, 654, 321, 111)"),
729 "222;321=111/456=789/987=654";
730is $a, 123;
731
732sub t051 ($a, $b, $c, @d) { "$a;$b;$c;".join("/", @d).";".scalar(@d) }
733is prototype(\&t051), undef;
734is eval("t051()"), undef;
ac7609e4 735like $@, qr/\AToo few arguments for subroutine 'main::t051' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 736is eval("t051(456)"), undef;
ac7609e4 737like $@, qr/\AToo few arguments for subroutine 'main::t051' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 738is eval("t051(456, 789)"), undef;
ac7609e4 739like $@, qr/\AToo few arguments for subroutine 'main::t051' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
740is eval("t051(456, 789, 987)"), "456;789;987;;0";
741is eval("t051(456, 789, 987, 654)"), "456;789;987;654;1";
742is eval("t051(456, 789, 987, 654, 321)"), "456;789;987;654/321;2";
743is eval("t051(456, 789, 987, 654, 321, 111)"), "456;789;987;654/321/111;3";
744is $a, 123;
745
746sub t052 ($a, $b, %c) { "$a;$b;".join("/", map { $_."=".$c{$_} } sort keys %c) }
747is prototype(\&t052), undef;
748is eval("t052()"), undef;
ac7609e4 749like $@, qr/\AToo few arguments for subroutine 'main::t052' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 750is eval("t052(222)"), undef;
ac7609e4 751like $@, qr/\AToo few arguments for subroutine 'main::t052' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
752is eval("t052(222, 333)"), "222;333;";
753is eval("t052(222, 333, 456)"), undef;
ac7609e4 754like $@, qr#\AOdd name/value argument for subroutine 'main::t052' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
755is eval("t052(222, 333, 456, 789)"), "222;333;456=789";
756is eval("t052(222, 333, 456, 789, 987)"), undef;
ac7609e4 757like $@, qr#\AOdd name/value argument for subroutine 'main::t052' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
758is eval("t052(222, 333, 456, 789, 987, 654)"), "222;333;456=789/987=654";
759is eval("t052(222, 333, 456, 789, 987, 654, 321)"), undef;
ac7609e4 760like $@, qr#\AOdd name/value argument for subroutine 'main::t052' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
761is eval("t052(222, 333, 456, 789, 987, 654, 321, 111)"),
762 "222;333;321=111/456=789/987=654";
763is $a, 123;
764
765sub t053 ($a, $b, $c, %d) {
766 "$a;$b;$c;".join("/", map { $_."=".$d{$_} } sort keys %d)
767}
768is prototype(\&t053), undef;
769is eval("t053()"), undef;
ac7609e4 770like $@, qr/\AToo few arguments for subroutine 'main::t053' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 771is eval("t053(222)"), undef;
ac7609e4 772like $@, qr/\AToo few arguments for subroutine 'main::t053' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 773is eval("t053(222, 333)"), undef;
ac7609e4 774like $@, qr/\AToo few arguments for subroutine 'main::t053' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
775is eval("t053(222, 333, 444)"), "222;333;444;";
776is eval("t053(222, 333, 444, 456)"), undef;
ac7609e4 777like $@, qr#\AOdd name/value argument for subroutine 'main::t053' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
778is eval("t053(222, 333, 444, 456, 789)"), "222;333;444;456=789";
779is eval("t053(222, 333, 444, 456, 789, 987)"), undef;
ac7609e4 780like $@, qr#\AOdd name/value argument for subroutine 'main::t053' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
781is eval("t053(222, 333, 444, 456, 789, 987, 654)"),
782 "222;333;444;456=789/987=654";
783is eval("t053(222, 333, 444, 456, 789, 987, 654, 321)"), undef;
ac7609e4 784like $@, qr#\AOdd name/value argument for subroutine 'main::t053' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
785is eval("t053(222, 333, 444, 456, 789, 987, 654, 321, 111)"),
786 "222;333;444;321=111/456=789/987=654";
787is $a, 123;
788
789sub t048 ($a = 222, @b) { $a.";".join("/", @b).";".scalar(@b) }
790is prototype(\&t048), undef;
791is eval("t048()"), "222;;0";
792is eval("t048(0)"), "0;;0";
793is eval("t048(456)"), "456;;0";
794is eval("t048(456, 789)"), "456;789;1";
795is eval("t048(456, 789, 987)"), "456;789/987;2";
796is eval("t048(456, 789, 987, 654)"), "456;789/987/654;3";
797is eval("t048(456, 789, 987, 654, 321)"), "456;789/987/654/321;4";
798is eval("t048(456, 789, 987, 654, 321, 111)"), "456;789/987/654/321/111;5";
799is $a, 123;
800
801sub t054 ($a = 222, $b = 333, @c) { "$a;$b;".join("/", @c).";".scalar(@c) }
802is prototype(\&t054), undef;
803is eval("t054()"), "222;333;;0";
804is eval("t054(456)"), "456;333;;0";
805is eval("t054(456, 789)"), "456;789;;0";
806is eval("t054(456, 789, 987)"), "456;789;987;1";
807is eval("t054(456, 789, 987, 654)"), "456;789;987/654;2";
808is eval("t054(456, 789, 987, 654, 321)"), "456;789;987/654/321;3";
809is eval("t054(456, 789, 987, 654, 321, 111)"), "456;789;987/654/321/111;4";
810is $a, 123;
811
812sub t055 ($a = 222, $b = 333, $c = 444, @d) {
813 "$a;$b;$c;".join("/", @d).";".scalar(@d)
814}
815is prototype(\&t055), undef;
816is eval("t055()"), "222;333;444;;0";
817is eval("t055(456)"), "456;333;444;;0";
818is eval("t055(456, 789)"), "456;789;444;;0";
819is eval("t055(456, 789, 987)"), "456;789;987;;0";
820is eval("t055(456, 789, 987, 654)"), "456;789;987;654;1";
821is eval("t055(456, 789, 987, 654, 321)"), "456;789;987;654/321;2";
822is eval("t055(456, 789, 987, 654, 321, 111)"), "456;789;987;654/321/111;3";
823is $a, 123;
824
825sub t050 ($a = 211, %b) { $a.";".join("/", map { $_."=".$b{$_} } sort keys %b) }
826is prototype(\&t050), undef;
827is eval("t050()"), "211;";
828is eval("t050(222)"), "222;";
829is eval("t050(222, 456)"), undef;
ac7609e4 830like $@, qr#\AOdd name/value argument for subroutine 'main::t050' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
831is eval("t050(222, 456, 789)"), "222;456=789";
832is eval("t050(222, 456, 789, 987)"), undef;
ac7609e4 833like $@, qr#\AOdd name/value argument for subroutine 'main::t050' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
834is eval("t050(222, 456, 789, 987, 654)"), "222;456=789/987=654";
835is eval("t050(222, 456, 789, 987, 654, 321)"), undef;
ac7609e4 836like $@, qr#\AOdd name/value argument for subroutine 'main::t050' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
837is eval("t050(222, 456, 789, 987, 654, 321, 111)"),
838 "222;321=111/456=789/987=654";
839is $a, 123;
840
841sub t056 ($a = 211, $b = 311, %c) {
842 "$a;$b;".join("/", map { $_."=".$c{$_} } sort keys %c)
843}
844is prototype(\&t056), undef;
845is eval("t056()"), "211;311;";
846is eval("t056(222)"), "222;311;";
847is eval("t056(222, 333)"), "222;333;";
848is eval("t056(222, 333, 456)"), undef;
ac7609e4 849like $@, qr#\AOdd name/value argument for subroutine 'main::t056' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
850is eval("t056(222, 333, 456, 789)"), "222;333;456=789";
851is eval("t056(222, 333, 456, 789, 987)"), undef;
ac7609e4 852like $@, qr#\AOdd name/value argument for subroutine 'main::t056' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
853is eval("t056(222, 333, 456, 789, 987, 654)"), "222;333;456=789/987=654";
854is eval("t056(222, 333, 456, 789, 987, 654, 321)"), undef;
ac7609e4 855like $@, qr#\AOdd name/value argument for subroutine 'main::t056' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
856is eval("t056(222, 333, 456, 789, 987, 654, 321, 111)"),
857 "222;333;321=111/456=789/987=654";
858is $a, 123;
859
860sub t057 ($a = 211, $b = 311, $c = 411, %d) {
861 "$a;$b;$c;".join("/", map { $_."=".$d{$_} } sort keys %d)
862}
863is prototype(\&t057), undef;
864is eval("t057()"), "211;311;411;";
865is eval("t057(222)"), "222;311;411;";
866is eval("t057(222, 333)"), "222;333;411;";
867is eval("t057(222, 333, 444)"), "222;333;444;";
868is eval("t057(222, 333, 444, 456)"), undef;
ac7609e4 869like $@, qr#\AOdd name/value argument for subroutine 'main::t057' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
870is eval("t057(222, 333, 444, 456, 789)"), "222;333;444;456=789";
871is eval("t057(222, 333, 444, 456, 789, 987)"), undef;
ac7609e4 872like $@, qr#\AOdd name/value argument for subroutine 'main::t057' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
873is eval("t057(222, 333, 444, 456, 789, 987, 654)"),
874 "222;333;444;456=789/987=654";
875is eval("t057(222, 333, 444, 456, 789, 987, 654, 321)"), undef;
ac7609e4 876like $@, qr#\AOdd name/value argument for subroutine 'main::t057' at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
877is eval("t057(222, 333, 444, 456, 789, 987, 654, 321, 111)"),
878 "222;333;444;321=111/456=789/987=654";
879is $a, 123;
880
881sub t058 ($a, $b = 333, @c) { "$a;$b;".join("/", @c).";".scalar(@c) }
882is prototype(\&t058), undef;
883is eval("t058()"), undef;
ac7609e4 884like $@, qr/\AToo few arguments for subroutine 'main::t058' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
885is eval("t058(456)"), "456;333;;0";
886is eval("t058(456, 789)"), "456;789;;0";
887is eval("t058(456, 789, 987)"), "456;789;987;1";
888is eval("t058(456, 789, 987, 654)"), "456;789;987/654;2";
889is eval("t058(456, 789, 987, 654, 321)"), "456;789;987/654/321;3";
890is eval("t058(456, 789, 987, 654, 321, 111)"), "456;789;987/654/321/111;4";
891is $a, 123;
892
893eval "#line 8 foo\nsub t059 (\@a, \$b) { }";
d3d9da4a 894is $@, qq{Slurpy parameter not last at foo line 8, near "\$b) "\n};
30d9c59b
Z
895
896eval "#line 8 foo\nsub t060 (\@a, \$b = 222) { }";
d3d9da4a 897is $@, qq{Slurpy parameter not last at foo line 8, near "222) "\n};
30d9c59b
Z
898
899eval "#line 8 foo\nsub t061 (\@a, \@b) { }";
d3d9da4a 900is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "\@b) "\n};
30d9c59b
Z
901
902eval "#line 8 foo\nsub t062 (\@a, \%b) { }";
d3d9da4a 903is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "%b) "\n};
30d9c59b
Z
904
905eval "#line 8 foo\nsub t063 (\@, \$b) { }";
d3d9da4a 906is $@, qq{Slurpy parameter not last at foo line 8, near "\$b) "\n};
30d9c59b
Z
907
908eval "#line 8 foo\nsub t064 (\@, \$b = 222) { }";
d3d9da4a 909is $@, qq{Slurpy parameter not last at foo line 8, near "222) "\n};
30d9c59b
Z
910
911eval "#line 8 foo\nsub t065 (\@, \@b) { }";
d3d9da4a 912is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "\@b) "\n};
30d9c59b
Z
913
914eval "#line 8 foo\nsub t066 (\@, \%b) { }";
d3d9da4a 915is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "%b) "\n};
30d9c59b
Z
916
917eval "#line 8 foo\nsub t067 (\@a, \$) { }";
d3d9da4a 918is $@, qq{Slurpy parameter not last at foo line 8, near "\$) "\n};
30d9c59b
Z
919
920eval "#line 8 foo\nsub t068 (\@a, \$ = 222) { }";
d3d9da4a 921is $@, qq{Slurpy parameter not last at foo line 8, near "222) "\n};
30d9c59b
Z
922
923eval "#line 8 foo\nsub t069 (\@a, \@) { }";
d3d9da4a 924is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "\@) "\n};
30d9c59b
Z
925
926eval "#line 8 foo\nsub t070 (\@a, \%) { }";
d3d9da4a 927is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "\%) "\n};
30d9c59b
Z
928
929eval "#line 8 foo\nsub t071 (\@, \$) { }";
d3d9da4a 930is $@, qq{Slurpy parameter not last at foo line 8, near "\$) "\n};
30d9c59b
Z
931
932eval "#line 8 foo\nsub t072 (\@, \$ = 222) { }";
d3d9da4a 933is $@, qq{Slurpy parameter not last at foo line 8, near "222) "\n};
30d9c59b
Z
934
935eval "#line 8 foo\nsub t073 (\@, \@) { }";
d3d9da4a 936is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "\@) "\n};
30d9c59b
Z
937
938eval "#line 8 foo\nsub t074 (\@, \%) { }";
d3d9da4a 939is $@, qq{Multiple slurpy parameters not allowed at foo line 8, near "\%) "\n};
30d9c59b
Z
940
941eval "#line 8 foo\nsub t075 (\%a, \$b) { }";
d3d9da4a 942is $@, qq{Slurpy parameter not last at foo line 8, near "\$b) "\n};
30d9c59b
Z
943
944eval "#line 8 foo\nsub t076 (\%, \$b) { }";
d3d9da4a 945is $@, qq{Slurpy parameter not last at foo line 8, near "\$b) "\n};
30d9c59b
Z
946
947eval "#line 8 foo\nsub t077 (\$a, \@b, \$c) { }";
d3d9da4a 948is $@, qq{Slurpy parameter not last at foo line 8, near "\$c) "\n};
30d9c59b
Z
949
950eval "#line 8 foo\nsub t078 (\$a, \%b, \$c) { }";
d3d9da4a 951is $@, qq{Slurpy parameter not last at foo line 8, near "\$c) "\n};
30d9c59b
Z
952
953eval "#line 8 foo\nsub t079 (\$a, \@b, \$c, \$d) { }";
d3d9da4a
DM
954is $@, <<EOF;
955Slurpy parameter not last at foo line 8, near "\$c,"
956Slurpy parameter not last at foo line 8, near "\$d) "
957EOF
30d9c59b
Z
958
959sub t080 ($a,,, $b) { $a.$b }
960is prototype(\&t080), undef;
961is eval("t080()"), undef;
ac7609e4 962like $@, qr/\AToo few arguments for subroutine 'main::t080' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 963is eval("t080(456)"), undef;
ac7609e4 964like $@, qr/\AToo few arguments for subroutine 'main::t080' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
965is eval("t080(456, 789)"), "456789";
966is eval("t080(456, 789, 987)"), undef;
ac7609e4 967like $@, qr/\AToo many arguments for subroutine 'main::t080' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 968is eval("t080(456, 789, 987, 654)"), undef;
ac7609e4 969like $@, qr/\AToo many arguments for subroutine 'main::t080' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
970is $a, 123;
971
972sub t081 ($a, $b,,) { $a.$b }
973is prototype(\&t081), undef;
974is eval("t081()"), undef;
ac7609e4 975like $@, qr/\AToo few arguments for subroutine 'main::t081' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 976is eval("t081(456)"), undef;
ac7609e4 977like $@, qr/\AToo few arguments for subroutine 'main::t081' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
978is eval("t081(456, 789)"), "456789";
979is eval("t081(456, 789, 987)"), undef;
ac7609e4 980like $@, qr/\AToo many arguments for subroutine 'main::t081' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 981is eval("t081(456, 789, 987, 654)"), undef;
ac7609e4 982like $@, qr/\AToo many arguments for subroutine 'main::t081' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
983is $a, 123;
984
985eval "#line 8 foo\nsub t082 (, \$a) { }";
d3d9da4a 986is $@, qq{syntax error at foo line 8, near "(,"\n};
30d9c59b
Z
987
988eval "#line 8 foo\nsub t083 (,) { }";
d3d9da4a 989is $@, qq{syntax error at foo line 8, near "(,"\n};
30d9c59b
Z
990
991sub t084($a,$b){ $a.$b }
992is prototype(\&t084), undef;
993is eval("t084()"), undef;
ac7609e4 994like $@, qr/\AToo few arguments for subroutine 'main::t084' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 995is eval("t084(456)"), undef;
ac7609e4 996like $@, qr/\AToo few arguments for subroutine 'main::t084' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
997is eval("t084(456, 789)"), "456789";
998is eval("t084(456, 789, 987)"), undef;
ac7609e4 999like $@, qr/\AToo many arguments for subroutine 'main::t084' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1000is eval("t084(456, 789, 987, 654)"), undef;
ac7609e4 1001like $@, qr/\AToo many arguments for subroutine 'main::t084' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1002is $a, 123;
1003
1004sub t085
1005 (
1006 $
1007 a
1008 ,
1009 ,
1010 $
1011 b
1012 =
1013 333
1014 ,
1015 ,
1016 )
1017 { $a.$b }
1018is prototype(\&t085), undef;
1019is eval("t085()"), undef;
ac7609e4 1020like $@, qr/\AToo few arguments for subroutine 'main::t085' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1021is eval("t085(456)"), "456333";
1022is eval("t085(456, 789)"), "456789";
1023is eval("t085(456, 789, 987)"), undef;
ac7609e4 1024like $@, qr/\AToo many arguments for subroutine 'main::t085' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1025is eval("t085(456, 789, 987, 654)"), undef;
ac7609e4 1026like $@, qr/\AToo many arguments for subroutine 'main::t085' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1027is $a, 123;
1028
1029sub t086
1030 ( #foo)))
1031 $ #foo)))
1032 a #foo)))
1033 , #foo)))
1034 , #foo)))
1035 $ #foo)))
1036 b #foo)))
1037 = #foo)))
1038 333 #foo)))
1039 , #foo)))
1040 , #foo)))
1041 ) #foo)))
1042 { $a.$b }
1043is prototype(\&t086), undef;
1044is eval("t086()"), undef;
ac7609e4 1045like $@, qr/\AToo few arguments for subroutine 'main::t086' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1046is eval("t086(456)"), "456333";
1047is eval("t086(456, 789)"), "456789";
1048is eval("t086(456, 789, 987)"), undef;
ac7609e4 1049like $@, qr/\AToo many arguments for subroutine 'main::t086' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1050is eval("t086(456, 789, 987, 654)"), undef;
ac7609e4 1051like $@, qr/\AToo many arguments for subroutine 'main::t086' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1052is $a, 123;
1053
1054sub t087
1055 (#foo)))
1056 $ #foo)))
1057 a#foo)))
1058 ,#foo)))
1059 ,#foo)))
1060 $ #foo)))
1061 b#foo)))
1062 =#foo)))
1063 333#foo)))
1064 ,#foo)))
1065 ,#foo)))
1066 )#foo)))
1067 { $a.$b }
1068is prototype(\&t087), undef;
1069is eval("t087()"), undef;
ac7609e4 1070like $@, qr/\AToo few arguments for subroutine 'main::t087' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1071is eval("t087(456)"), "456333";
1072is eval("t087(456, 789)"), "456789";
1073is eval("t087(456, 789, 987)"), undef;
ac7609e4 1074like $@, qr/\AToo many arguments for subroutine 'main::t087' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1075is eval("t087(456, 789, 987, 654)"), undef;
ac7609e4 1076like $@, qr/\AToo many arguments for subroutine 'main::t087' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1077is $a, 123;
1078
1079eval "#line 8 foo\nsub t088 (\$ #foo\na) { }";
1080is $@, "";
1081
d3d9da4a 1082
30d9c59b 1083eval "#line 8 foo\nsub t089 (\$#foo\na) { }";
d3d9da4a 1084like $@, qr{\A'#' not allowed immediately following a sigil in a subroutine signature at foo line 8, near "\(\$"\n};
30d9c59b
Z
1085
1086eval "#line 8 foo\nsub t090 (\@ #foo\na) { }";
1087is $@, "";
1088
1089eval "#line 8 foo\nsub t091 (\@#foo\na) { }";
d3d9da4a 1090like $@, qr{\A'#' not allowed immediately following a sigil in a subroutine signature at foo line 8, near "\(\@"\n};
30d9c59b
Z
1091
1092eval "#line 8 foo\nsub t092 (\% #foo\na) { }";
1093is $@, "";
1094
1095eval "#line 8 foo\nsub t093 (\%#foo\na) { }";
d3d9da4a 1096like $@, qr{\A'#' not allowed immediately following a sigil in a subroutine signature at foo line 8, near "\(%"\n};
30d9c59b
Z
1097
1098eval "#line 8 foo\nsub t094 (123) { }";
bb6b75cd 1099like $@, qr{\AA signature parameter must start with '\$', '\@' or '%' at foo line 8, near "\(1"\n};
30d9c59b
Z
1100
1101eval "#line 8 foo\nsub t095 (\$a, 123) { }";
d3d9da4a 1102is $@, <<EOF;
bb6b75cd 1103A signature parameter must start with '\$', '\@' or '%' at foo line 8, near ", 1"
d3d9da4a
DM
1104syntax error at foo line 8, near ", 123"
1105EOF
30d9c59b 1106
71986b33 1107eval "#line 8 foo\nno warnings; sub t096 (\$a 123) { }";
08ccc810
TC
1108is $@, <<'EOF';
1109Illegal operator following parameter in a subroutine signature at foo line 8, near "($a 123"
1110syntax error at foo line 8, near "($a 123"
1111EOF
30d9c59b
Z
1112
1113eval "#line 8 foo\nsub t097 (\$a { }) { }";
08ccc810
TC
1114is $@, <<'EOF';
1115Illegal operator following parameter in a subroutine signature at foo line 8, near "($a { }"
1116syntax error at foo line 8, near "($a { }"
d3d9da4a 1117EOF
30d9c59b
Z
1118
1119eval "#line 8 foo\nsub t098 (\$a; \$b) { }";
08ccc810
TC
1120is $@, <<'EOF';
1121Illegal operator following parameter in a subroutine signature at foo line 8, near "($a; "
1122syntax error at foo line 8, near "($a; "
d3d9da4a 1123EOF
30d9c59b
Z
1124
1125eval "#line 8 foo\nsub t099 (\$\$) { }";
d3d9da4a 1126is $@, <<EOF;
bb6b75cd 1127Illegal character following sigil in a subroutine signature at foo line 8, near "(\$"
49fb8620 1128syntax error at foo line 8, near "\$\$) "
d3d9da4a 1129EOF
30d9c59b 1130
30d9c59b
Z
1131eval "#line 8 foo\nsub t101 (\@_) { }";
1132like $@, qr/\ACan't use global \@_ in "my" at foo line 8/;
1133
1134eval "#line 8 foo\nsub t102 (\%_) { }";
1135like $@, qr/\ACan't use global \%_ in "my" at foo line 8/;
1136
1137my $t103 = sub ($a) { $a || "z" };
1138is prototype($t103), undef;
1139is eval("\$t103->()"), undef;
ac7609e4 1140like $@, qr/\AToo few arguments for subroutine 'main::__ANON__' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1141is eval("\$t103->(0)"), "z";
1142is eval("\$t103->(456)"), 456;
1143is eval("\$t103->(456, 789)"), undef;
ac7609e4 1144like $@, qr/\AToo many arguments for subroutine 'main::__ANON__' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1145is eval("\$t103->(456, 789, 987)"), undef;
ac7609e4 1146like $@, qr/\AToo many arguments for subroutine 'main::__ANON__' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1147is $a, 123;
1148
894f226e 1149my $t118 = sub :prototype($) ($a) { $a || "z" };
30d9c59b
Z
1150is prototype($t118), "\$";
1151is eval("\$t118->()"), undef;
ac7609e4 1152like $@, qr/\AToo few arguments for subroutine 'main::__ANON__' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1153is eval("\$t118->(0)"), "z";
1154is eval("\$t118->(456)"), 456;
1155is eval("\$t118->(456, 789)"), undef;
ac7609e4 1156like $@, qr/\AToo many arguments for subroutine 'main::__ANON__' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1157is eval("\$t118->(456, 789, 987)"), undef;
ac7609e4 1158like $@, qr/\AToo many arguments for subroutine 'main::__ANON__' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1159is $a, 123;
1160
1161sub t033 ($a = sub ($a) { $a."z" }) { $a->("a")."y" }
1162is prototype(\&t033), undef;
1163is eval("t033()"), "azy";
1164is eval("t033(sub { \"x\".\$_[0].\"x\" })"), "xaxy";
1165is eval("t033(sub { \"x\".\$_[0].\"x\" }, 789)"), undef;
ac7609e4 1166like $@, qr/\AToo many arguments for subroutine 'main::t033' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1167is $a, 123;
1168
863e3089
Z
1169sub t133 ($a = sub ($a = 222) { $a."z" }) { $a->()."/".$a->("a") }
1170is prototype(\&t133), undef;
1171is eval("t133()"), "222z/az";
1172is eval("t133(sub { \"x\".(\$_[0] // \"u\").\"x\" })"), "xux/xax";
1173is eval("t133(sub { \"x\".(\$_[0] // \"u\").\"x\" }, 789)"), undef;
ac7609e4 1174like $@, qr/\AToo many arguments for subroutine 'main::t133' at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1175is $a, 123;
1176
1177sub t134 ($a = sub ($a, $t = sub { $_[0]."p" }) { $t->($a)."z" }) {
1178 $a->("a")."/".$a->("b", sub { $_[0]."q" } )
1179}
1180is prototype(\&t134), undef;
1181is eval("t134()"), "apz/bqz";
1182is eval("t134(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" })"),
1183 "xax/xbqx";
1184is eval("t134(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" }, 789)"),
1185 undef;
ac7609e4 1186like $@, qr/\AToo many arguments for subroutine 'main::t134' at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1187is $a, 123;
1188
1189sub t135 ($a = sub ($a, $t = sub ($p) { $p."p" }) { $t->($a)."z" }) {
1190 $a->("a")."/".$a->("b", sub { $_[0]."q" } )
1191}
1192is prototype(\&t135), undef;
1193is eval("t135()"), "apz/bqz";
1194is eval("t135(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" })"),
1195 "xax/xbqx";
1196is eval("t135(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" }, 789)"),
1197 undef;
ac7609e4 1198like $@, qr/\AToo many arguments for subroutine 'main::t135' at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1199is $a, 123;
1200
1201sub t132 (
1202 $a = sub ($a, $t = sub ($p = 222) { $p."p" }) { $t->($a)."z".$t->() },
1203) {
1204 $a->("a")."/".$a->("b", sub { ($_[0] // "u")."q" } )
1205}
1206is prototype(\&t132), undef;
1207is eval("t132()"), "apz222p/bqzuq";
1208is eval("t132(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" })"),
1209 "xax/xbqx";
1210is eval("t132(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" }, 789)"),
1211 undef;
ac7609e4 1212like $@, qr/\AToo many arguments for subroutine 'main::t132' at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1213is $a, 123;
1214
894f226e 1215sub t104 :method ($a) { $a || "z" }
30d9c59b
Z
1216is prototype(\&t104), undef;
1217is eval("t104()"), undef;
ac7609e4 1218like $@, qr/\AToo few arguments for subroutine 'main::t104' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1219is eval("t104(0)"), "z";
1220is eval("t104(456)"), 456;
1221is eval("t104(456, 789)"), undef;
ac7609e4 1222like $@, qr/\AToo many arguments for subroutine 'main::t104' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1223is eval("t104(456, 789, 987)"), undef;
ac7609e4 1224like $@, qr/\AToo many arguments for subroutine 'main::t104' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1225is $a, 123;
1226
894f226e 1227sub t105 :prototype($) ($a) { $a || "z" }
30d9c59b
Z
1228is prototype(\&t105), "\$";
1229is eval("t105()"), undef;
1230like $@, qr/\ANot enough arguments for main::t105 /;
1231is eval("t105(0)"), "z";
1232is eval("t105(456)"), 456;
1233is eval("t105(456, 789)"), undef;
aff539aa 1234like $@, qr/\AToo many arguments for main::t105 at \(eval \d+\) line 1, near/;
30d9c59b 1235is eval("t105(456, 789, 987)"), undef;
aff539aa 1236like $@, qr/\AToo many arguments for main::t105 at \(eval \d+\) line 1, near/;
30d9c59b
Z
1237is $a, 123;
1238
894f226e 1239sub t106 :prototype(@) ($a) { $a || "z" }
30d9c59b
Z
1240is prototype(\&t106), "\@";
1241is eval("t106()"), undef;
ac7609e4 1242like $@, qr/\AToo few arguments for subroutine 'main::t106' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1243is eval("t106(0)"), "z";
1244is eval("t106(456)"), 456;
1245is eval("t106(456, 789)"), undef;
ac7609e4 1246like $@, qr/\AToo many arguments for subroutine 'main::t106' at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1247is eval("t106(456, 789, 987)"), undef;
ac7609e4 1248like $@, qr/\AToo many arguments for subroutine 'main::t106' at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1249is $a, 123;
1250
894f226e 1251eval "#line 8 foo\nsub t107(\$a) :method { }";
30d9c59b
Z
1252isnt $@, "";
1253
894f226e 1254eval "#line 8 foo\nsub t108 (\$a) :prototype(\$) { }";
30d9c59b
Z
1255isnt $@, "";
1256
1257sub t109 { }
1258is prototype(\&t109), undef;
1259is scalar(@{[ t109() ]}), 0;
1260is scalar(t109()), undef;
1261
1262sub t110 () { }
1263is prototype(\&t110), undef;
1264is scalar(@{[ t110() ]}), 0;
1265is scalar(t110()), undef;
1266
1267sub t111 ($a) { }
1268is prototype(\&t111), undef;
1269is scalar(@{[ t111(222) ]}), 0;
1270is scalar(t111(222)), undef;
1271
1272sub t112 ($) { }
1273is prototype(\&t112), undef;
1274is scalar(@{[ t112(222) ]}), 0;
1275is scalar(t112(222)), undef;
1276
1277sub t114 ($a = undef) { }
1278is prototype(\&t114), undef;
1279is scalar(@{[ t114() ]}), 0;
1280is scalar(t114()), undef;
1281is scalar(@{[ t114(333) ]}), 0;
1282is scalar(t114(333)), undef;
1283
1284sub t113 ($a = 222) { }
1285is prototype(\&t113), undef;
1286is scalar(@{[ t113() ]}), 0;
1287is scalar(t113()), undef;
1288is scalar(@{[ t113(333) ]}), 0;
1289is scalar(t113(333)), undef;
1290
1291sub t115 ($a = do { $z++; 222 }) { }
1292is prototype(\&t115), undef;
1293$z = 0;
1294is scalar(@{[ t115() ]}), 0;
1295is $z, 1;
1296is scalar(t115()), undef;
1297is $z, 2;
1298is scalar(@{[ t115(333) ]}), 0;
1299is scalar(t115(333)), undef;
1300is $z, 2;
1301
1302sub t116 (@a) { }
1303is prototype(\&t116), undef;
1304is scalar(@{[ t116() ]}), 0;
1305is scalar(t116()), undef;
1306is scalar(@{[ t116(333) ]}), 0;
1307is scalar(t116(333)), undef;
1308
1309sub t117 (%a) { }
1310is prototype(\&t117), undef;
1311is scalar(@{[ t117() ]}), 0;
1312is scalar(t117()), undef;
1313is scalar(@{[ t117(333, 444) ]}), 0;
1314is scalar(t117(333, 444)), undef;
1315
4fa06845
DM
1316sub t145 ($=3) { }
1317is scalar(t145()), undef;
1318
1319{
1320 my $want;
1321 sub want { $want = wantarray ? "list"
1322 : defined(wantarray) ? "scalar" : "void"; 1 }
1323
1324 sub t144 ($a = want()) { $a }
1325 t144();
1326 is ($want, "scalar", "default expression is scalar in void context");
1327 my $x = t144();
1328 is ($want, "scalar", "default expression is scalar in scalar context");
1329 () = t144();
1330 is ($want, "scalar", "default expression is scalar in list context");
1331}
1332
f6ca42c7
DM
1333
1334# check for default arg code doing nasty things (closures, gotos,
1335# modifying @_ etc).
1336
1337{
1338 no warnings qw(closure);
1339 use Tie::Array;
1340 use Tie::Hash;
1341
1342 sub t146 ($a = t146x()) {
1343 sub t146x { $a = "abc"; 1 }
1344 $a;
1345 }
1346 is t146(), 1, "t146: closure can make new lexical not undef";
1347
1348 sub t147 ($a = t147x()) {
1349 sub t147x { $a = "abc"; pos($a)=1; 1 }
1350 is pos($a), undef, "t147: pos magic cleared";
1351 $a;
1352 }
1353 is t147(), 1, "t147: closure can make new lexical not undef and magical";
1354
1355 sub t148 ($a = t148x()) {
1356 sub t148x { $a = []; 1 }
1357 $a;
1358 }
1359 is t148(), 1, "t148: closure can make new lexical a ref";
1360
1361 sub t149 ($a = t149x()) {
1362 sub t149x { $a = 1; [] }
1363 $a;
1364 }
1365 is ref(t149()), "ARRAY", "t149: closure can make new lexical a ref";
1366
1367 sub t150 ($a = do {@_ = qw(a b c); 1}, $b = 2) {
1368 is $a, 1, "t150: a: growing \@_";
1369 is $b, "b", "t150: b: growing \@_";
1370 }
1371 t150();
1372
1373
1374 sub t151 ($a = do {tie @_, 'Tie::StdArray'; @_ = qw(a b c); 1}, $b = 2) {
1375 is $a, 1, "t151: a: tied \@_";
1376 is $b, "b", "t151: b: tied \@_";
1377 }
1378 t151();
1379
1380 sub t152 ($a = t152x(), @b) {
1381 sub t152x { @b = qw(a b c); 1 }
1382 $a . '-' . join(':', @b);
1383 }
1384 is t152(), "1-", "t152: closure can make new lexical array non-empty";
1385
1386 sub t153 ($a = t153x(), %b) {
1387 sub t153x { %b = qw(a 10 b 20); 1 }
1388 $a . '-' . join(':', sort %b);
1389 }
1390 is t153(), "1-", "t153: closure can make new lexical hash non-empty";
1391
1392 sub t154 ($a = t154x(), @b) {
1393 sub t154x { tie @b, 'Tie::StdArray'; @b = qw(a b c); 1 }
1394 $a . '-' . join(':', @b);
1395 }
1396 is t154(), "1-", "t154: closure can make new lexical array tied";
1397
1398 sub t155 ($a = t155x(), %b) {
1399 sub t155x { tie %b, 'Tie::StdHash'; %b = qw(a 10 b 20); 1 }
1400 $a . '-' . join(':', sort %b);
1401 }
1402 is t155(), "1-", "t155: closure can make new lexical hash tied";
1403
1404 sub t156 ($a = do {@_ = qw(a b c); 1}, @b) {
1405 is $a, 1, "t156: a: growing \@_";
1406 is "@b", "b c", "t156: b: growing \@_";
1407 }
1408 t156();
1409
1410 sub t157 ($a = do {@_ = qw(a b c); 1}, %b) {
1411 is $a, 1, "t157: a: growing \@_";
1412 is join(':', sort %b), "b:c", "t157: b: growing \@_";
1413 }
1414 t157();
1415
1416 sub t158 ($a = do {tie @_, 'Tie::StdArray'; @_ = qw(a b c); 1}, @b) {
1417 is $a, 1, "t158: a: tied \@_";
1418 is "@b", "b c", "t158: b: tied \@_";
1419 }
1420 t158();
1421
1422 sub t159 ($a = do {tie @_, 'Tie::StdArray'; @_ = qw(a b c); 1}, %b) {
1423 is $a, 1, "t159: a: tied \@_";
1424 is join(':', sort %b), "b:c", "t159: b: tied \@_";
1425 }
1426 t159();
1427
1428 # see if we can handle the equivalent of @a = ($a[1], $a[0])
1429
1430 sub t160 ($s, @a) {
1431 sub t160x {
1432 @a = qw(x y);
1433 t160(1, $a[1], $a[0]);
1434 }
1435 # encourage recently-freed SVPVs to be realloced with new values
1436 my @pad = qw(a b);
1437 join ':', $s, @a;
1438 }
1439 is t160x(), "1:y:x", 'handle commonality in slurpy array';
1440
1441 # see if we can handle the equivalent of %h = ('foo', $h{foo})
1442
1443 sub t161 ($s, %h) {
1444 sub t161x {
1445 %h = qw(k1 v1 k2 v2);
1446 t161(1, k1 => $h{k2}, k2 => $h{k1});
1447 }
1448 # encourage recently-freed SVPVs to be realloced with new values
1449 my @pad = qw(a b);
1450 join ' ', $s, map "($_,$h{$_})", sort keys %h;
1451 }
1452 is t161x(), "1 (k1,v2) (k2,v1)", 'handle commonality in slurpy hash';
1453
1454 # see if we can handle the equivalent of ($a,$b) = ($b,$a)
1455 # Note that for non-signatured subs, my ($a,$b) = @_ already fails the
1456 # equivalent of this test too, since I skipped pessimising it
1457 # (90ce4d057857) as commonality in this case is rare and contrived,
1458 # as the example below shows. DAPM.
1459 sub t162 ($a, $b) {
1460 sub t162x {
1461 ($a, $b) = qw(x y);
1462 t162($b, $a);
1463 }
1464 "$a:$b";
1465 }
1466 {
71986b33 1467 local $::TODO = q{can't handle commonaility};
f6ca42c7
DM
1468 is t162x(), "y:x", 'handle commonality in scalar parms';
1469 }
f6ca42c7
DM
1470}
1471
d79f31b5
DM
1472{
1473 my $w;
d79f31b5
DM
1474 local $SIG{__WARN__} = sub { $w .= "@_" };
1475 is eval q{sub ($x,$x) { $x}->(1,2)}, 2, "duplicate sig var names";
1476 like $w, qr/^"my" variable \$x masks earlier declaration in same scope/,
1477 "masking warning";
1478}
1479
ac7609e4
AC
1480# Reporting subroutine names
1481
1482package T200 {
1483 sub foo ($x) {}
1484 *t201 = sub ($x) {}
1485}
1486*t202 = sub ($x) {};
1487my $t203 = sub ($x) {};
1488*t204 = *T200::foo;
1489*t205 = \&T200::foo;
1490
1491eval { T200::foo() };
1492like($@, qr/^Too few arguments for subroutine 'T200::foo'/);
1493eval { T200::t201() };
1494like($@, qr/^Too few arguments for subroutine 'T200::__ANON__'/);
1495eval { t202() };
1496like($@, qr/^Too few arguments for subroutine 'main::__ANON__'/);
1497eval { $t203->() };
1498like($@, qr/^Too few arguments for subroutine 'main::__ANON__'/);
1499eval { t204() };
1500like($@, qr/^Too few arguments for subroutine 'T200::foo'/);
1501eval { t205() };
1502like($@, qr/^Too few arguments for subroutine 'T200::foo'/);
1503
1504
cbf40e71
DM
1505# RT #130661 a char >= 0x80 in a signature when a sigil was expected
1506# was triggering an assertion
1507
1508eval "sub (\x80";
1509like $@, qr/A signature parameter must start with/, "RT #130661";
1510
f6ca42c7
DM
1511
1512
1ccc3f31
FC
1513use File::Spec::Functions;
1514my $keywords_file = catfile(updir,'regen','keywords.pl');
1515open my $kh, $keywords_file
1516 or die "$0 cannot open $keywords_file: $!";
1517while(<$kh>) {
1518 if (m?__END__?..${\0} and /^[+-]/) {
1519 chomp(my $word = $');
1520 # $y should be an error after $x=foo. The exact error we get may
1521 # differ if this is __END__ or s or some other special keyword.
71986b33 1522 eval 'no warnings; sub ($x = ' . $word . ', $y) {}';
1ccc3f31
FC
1523 isnt $@, "", "$word does not swallow trailing comma";
1524 }
1525}
1526
894f226e
DM
1527# RT #132141
1528# Attributes such as lvalue have to come *before* the signature to
1529# ensure that they're applied to any code block within the signature
1530
1531{
1532 my $x;
1533 sub f :lvalue ($a = do { $x = "abc"; return substr($x,0,1)}) {
1534 die; # notreached
1535 }
1536
1537 f() = "X";
1538 is $x, "Xbc", "RT #132141";
1539}
1540
1541
1ccc3f31
FC
1542done_testing;
1543
30d9c59b 15441;