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