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