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