This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Um, finish reordering the parser struct
[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
Z
417eval "#line 8 foo\nsub t024 (\$a =) { }";
418is $@, "Optional parameter lacks default expression at foo line 8\.\n";
419
420sub t025 ($ = undef) { $a // "z" }
421is prototype(\&t025), undef;
422is eval("t025()"), 123;
423is eval("t025(0)"), 123;
424is eval("t025(456)"), 123;
425is eval("t025(456, 789)"), undef;
aff539aa 426like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 427is eval("t025(456, 789, 987)"), undef;
aff539aa 428like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 429is eval("t025(456, 789, 987, 654)"), undef;
aff539aa 430like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
431is $a, 123;
432
433sub t026 ($ = 222) { $a // "z" }
434is prototype(\&t026), undef;
435is eval("t026()"), 123;
436is eval("t026(0)"), 123;
437is eval("t026(456)"), 123;
438is eval("t026(456, 789)"), undef;
aff539aa 439like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 440is eval("t026(456, 789, 987)"), undef;
aff539aa 441like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 442is eval("t026(456, 789, 987, 654)"), undef;
aff539aa 443like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
444is $a, 123;
445
446sub t032 ($ = do { $z++; 222 }) { $a // "z" }
447$z = 0;
448is prototype(\&t032), undef;
449is eval("t032()"), 123;
450is $z, 1;
451is eval("t032(0)"), 123;
452is eval("t032(456)"), 123;
453is eval("t032(456, 789)"), undef;
aff539aa 454like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 455is eval("t032(456, 789, 987)"), undef;
aff539aa 456like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 457is eval("t032(456, 789, 987, 654)"), undef;
aff539aa 458like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
459is $z, 1;
460is $a, 123;
461
462sub t027 ($ =) { $a // "z" }
463is prototype(\&t027), undef;
464is eval("t027()"), 123;
465is eval("t027(0)"), 123;
466is eval("t027(456)"), 123;
467is eval("t027(456, 789)"), undef;
aff539aa 468like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 469is eval("t027(456, 789, 987)"), undef;
aff539aa 470like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 471is eval("t027(456, 789, 987, 654)"), undef;
aff539aa 472like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
473is $a, 123;
474
475sub t119 ($ =, $a = 333) { $a // "z" }
476is prototype(\&t119), undef;
477is eval("t119()"), 333;
478is eval("t119(0)"), 333;
479is eval("t119(456)"), 333;
480is eval("t119(456, 789)"), 789;
481is eval("t119(456, 789, 987)"), undef;
aff539aa 482like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 483is eval("t119(456, 789, 987, 654)"), undef;
aff539aa 484like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
485is $a, 123;
486
487sub t028 ($a, $b = 333) { "$a/$b" }
488is prototype(\&t028), undef;
489is eval("t028()"), undef;
aff539aa 490like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
491is eval("t028(0)"), "0/333";
492is eval("t028(456)"), "456/333";
493is eval("t028(456, 789)"), "456/789";
494is eval("t028(456, 789, 987)"), undef;
aff539aa 495like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
496is $a, 123;
497
498sub t045 ($a, $ = 333) { "$a/" }
499is prototype(\&t045), undef;
500is eval("t045()"), undef;
aff539aa 501like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
502is eval("t045(0)"), "0/";
503is eval("t045(456)"), "456/";
504is eval("t045(456, 789)"), "456/";
505is eval("t045(456, 789, 987)"), undef;
aff539aa 506like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
507is $a, 123;
508
509sub t046 ($, $b = 333) { "$a/$b" }
510is prototype(\&t046), undef;
511is eval("t046()"), undef;
aff539aa 512like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
513is eval("t046(0)"), "123/333";
514is eval("t046(456)"), "123/333";
515is eval("t046(456, 789)"), "123/789";
516is eval("t046(456, 789, 987)"), undef;
aff539aa 517like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
518is $a, 123;
519
520sub t047 ($, $ = 333) { "$a/" }
521is prototype(\&t047), undef;
522is eval("t047()"), undef;
aff539aa 523like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
524is eval("t047(0)"), "123/";
525is eval("t047(456)"), "123/";
526is eval("t047(456, 789)"), "123/";
527is eval("t047(456, 789, 987)"), undef;
aff539aa 528like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
529is $a, 123;
530
531sub t029 ($a, $b, $c = 222, $d = 333) { "$a/$b/$c/$d" }
532is prototype(\&t029), undef;
533is eval("t029()"), undef;
aff539aa 534like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 535is eval("t029(0)"), undef;
aff539aa 536like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 537is eval("t029(456)"), undef;
aff539aa 538like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
539is eval("t029(456, 789)"), "456/789/222/333";
540is eval("t029(456, 789, 987)"), "456/789/987/333";
541is eval("t029(456, 789, 987, 654)"), "456/789/987/654";
542is eval("t029(456, 789, 987, 654, 321)"), undef;
aff539aa 543like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 544is eval("t029(456, 789, 987, 654, 321, 111)"), undef;
aff539aa 545like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
546is $a, 123;
547
548sub t038 ($a, $b = $a."x") { "$a/$b" }
549is prototype(\&t038), undef;
550is eval("t038()"), undef;
aff539aa 551like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
552is eval("t038(0)"), "0/0x";
553is eval("t038(456)"), "456/456x";
554is eval("t038(456, 789)"), "456/789";
555is eval("t038(456, 789, 987)"), undef;
aff539aa 556like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
557is $a, 123;
558
559eval "#line 8 foo\nsub t030 (\$a = 222, \$b) { }";
560is $@, "Mandatory parameter follows optional parameter at foo line 8\.\n";
561
562eval "#line 8 foo\nsub t031 (\$a = 222, \$b = 333, \$c, \$d) { }";
563is $@, "Mandatory parameter follows optional parameter at foo line 8\.\n";
564
565sub t034 (@abc) { join("/", @abc).";".scalar(@abc) }
566is prototype(\&t034), undef;
567is eval("t034()"), ";0";
568is eval("t034(0)"), "0;1";
569is eval("t034(456)"), "456;1";
570is eval("t034(456, 789)"), "456/789;2";
571is eval("t034(456, 789, 987)"), "456/789/987;3";
572is eval("t034(456, 789, 987, 654)"), "456/789/987/654;4";
573is eval("t034(456, 789, 987, 654, 321)"), "456/789/987/654/321;5";
574is eval("t034(456, 789, 987, 654, 321, 111)"), "456/789/987/654/321/111;6";
575is $a, 123;
576
863e3089
Z
577eval "#line 8 foo\nsub t136 (\@abc = 222) { }";
578like $@, qr/\AParse error at foo line 8\.\n/;
579
580eval "#line 8 foo\nsub t137 (\@abc =) { }";
581like $@, qr/\AParse error at foo line 8\.\n/;
582
30d9c59b
Z
583sub t035 (@) { $a }
584is prototype(\&t035), undef;
585is eval("t035()"), 123;
586is eval("t035(0)"), 123;
587is eval("t035(456)"), 123;
588is eval("t035(456, 789)"), 123;
589is eval("t035(456, 789, 987)"), 123;
590is eval("t035(456, 789, 987, 654)"), 123;
591is eval("t035(456, 789, 987, 654, 321)"), 123;
592is eval("t035(456, 789, 987, 654, 321, 111)"), 123;
593is $a, 123;
594
863e3089
Z
595eval "#line 8 foo\nsub t138 (\@ = 222) { }";
596like $@, qr/\AParse error at foo line 8\.\n/;
597
598eval "#line 8 foo\nsub t139 (\@ =) { }";
599like $@, qr/\AParse error at foo line 8\.\n/;
600
30d9c59b
Z
601sub t039 (%abc) { join("/", map { $_."=".$abc{$_} } sort keys %abc) }
602is prototype(\&t039), undef;
603is eval("t039()"), "";
604is eval("t039(0)"), undef;
aff539aa 605like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b 606is eval("t039(456)"), undef;
aff539aa 607like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
608is eval("t039(456, 789)"), "456=789";
609is eval("t039(456, 789, 987)"), undef;
aff539aa 610like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
611is eval("t039(456, 789, 987, 654)"), "456=789/987=654";
612is eval("t039(456, 789, 987, 654, 321)"), undef;
aff539aa 613like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
614is eval("t039(456, 789, 987, 654, 321, 111)"), "321=111/456=789/987=654";
615is $a, 123;
616
863e3089
Z
617eval "#line 8 foo\nsub t140 (\%abc = 222) { }";
618like $@, qr/\AParse error at foo line 8\.\n/;
619
620eval "#line 8 foo\nsub t141 (\%abc =) { }";
621like $@, qr/\AParse error at foo line 8\.\n/;
622
30d9c59b
Z
623sub t040 (%) { $a }
624is prototype(\&t040), undef;
625is eval("t040()"), 123;
626is eval("t040(0)"), undef;
aff539aa 627like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b 628is eval("t040(456)"), undef;
aff539aa 629like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
630is eval("t040(456, 789)"), 123;
631is eval("t040(456, 789, 987)"), undef;
aff539aa 632like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
633is eval("t040(456, 789, 987, 654)"), 123;
634is eval("t040(456, 789, 987, 654, 321)"), undef;
aff539aa 635like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
636is eval("t040(456, 789, 987, 654, 321, 111)"), 123;
637is $a, 123;
638
863e3089
Z
639eval "#line 8 foo\nsub t142 (\% = 222) { }";
640like $@, qr/\AParse error at foo line 8\.\n/;
641
642eval "#line 8 foo\nsub t143 (\% =) { }";
643like $@, qr/\AParse error at foo line 8\.\n/;
644
30d9c59b
Z
645sub t041 ($a, @b) { $a.";".join("/", @b) }
646is prototype(\&t041), undef;
647is eval("t041()"), undef;
aff539aa 648like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
649is eval("t041(0)"), "0;";
650is eval("t041(456)"), "456;";
651is eval("t041(456, 789)"), "456;789";
652is eval("t041(456, 789, 987)"), "456;789/987";
653is eval("t041(456, 789, 987, 654)"), "456;789/987/654";
654is eval("t041(456, 789, 987, 654, 321)"), "456;789/987/654/321";
655is eval("t041(456, 789, 987, 654, 321, 111)"), "456;789/987/654/321/111";
656is $a, 123;
657
658sub t042 ($a, @) { $a.";" }
659is prototype(\&t042), undef;
660is eval("t042()"), undef;
aff539aa 661like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
662is eval("t042(0)"), "0;";
663is eval("t042(456)"), "456;";
664is eval("t042(456, 789)"), "456;";
665is eval("t042(456, 789, 987)"), "456;";
666is eval("t042(456, 789, 987, 654)"), "456;";
667is eval("t042(456, 789, 987, 654, 321)"), "456;";
668is eval("t042(456, 789, 987, 654, 321, 111)"), "456;";
669is $a, 123;
670
671sub t043 ($, @b) { $a.";".join("/", @b) }
672is prototype(\&t043), undef;
673is eval("t043()"), undef;
aff539aa 674like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
675is eval("t043(0)"), "123;";
676is eval("t043(456)"), "123;";
677is eval("t043(456, 789)"), "123;789";
678is eval("t043(456, 789, 987)"), "123;789/987";
679is eval("t043(456, 789, 987, 654)"), "123;789/987/654";
680is eval("t043(456, 789, 987, 654, 321)"), "123;789/987/654/321";
681is eval("t043(456, 789, 987, 654, 321, 111)"), "123;789/987/654/321/111";
682is $a, 123;
683
684sub t044 ($, @) { $a.";" }
685is prototype(\&t044), undef;
686is eval("t044()"), undef;
aff539aa 687like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
688is eval("t044(0)"), "123;";
689is eval("t044(456)"), "123;";
690is eval("t044(456, 789)"), "123;";
691is eval("t044(456, 789, 987)"), "123;";
692is eval("t044(456, 789, 987, 654)"), "123;";
693is eval("t044(456, 789, 987, 654, 321)"), "123;";
694is eval("t044(456, 789, 987, 654, 321, 111)"), "123;";
695is $a, 123;
696
697sub t049 ($a, %b) { $a.";".join("/", map { $_."=".$b{$_} } sort keys %b) }
698is prototype(\&t049), undef;
699is eval("t049()"), undef;
aff539aa 700like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
701is eval("t049(222)"), "222;";
702is eval("t049(222, 456)"), undef;
aff539aa 703like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
704is eval("t049(222, 456, 789)"), "222;456=789";
705is eval("t049(222, 456, 789, 987)"), undef;
aff539aa 706like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
707is eval("t049(222, 456, 789, 987, 654)"), "222;456=789/987=654";
708is eval("t049(222, 456, 789, 987, 654, 321)"), undef;
aff539aa 709like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
710is eval("t049(222, 456, 789, 987, 654, 321, 111)"),
711 "222;321=111/456=789/987=654";
712is $a, 123;
713
714sub t051 ($a, $b, $c, @d) { "$a;$b;$c;".join("/", @d).";".scalar(@d) }
715is prototype(\&t051), undef;
716is eval("t051()"), undef;
aff539aa 717like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 718is eval("t051(456)"), undef;
aff539aa 719like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 720is eval("t051(456, 789)"), undef;
aff539aa 721like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
722is eval("t051(456, 789, 987)"), "456;789;987;;0";
723is eval("t051(456, 789, 987, 654)"), "456;789;987;654;1";
724is eval("t051(456, 789, 987, 654, 321)"), "456;789;987;654/321;2";
725is eval("t051(456, 789, 987, 654, 321, 111)"), "456;789;987;654/321/111;3";
726is $a, 123;
727
728sub t052 ($a, $b, %c) { "$a;$b;".join("/", map { $_."=".$c{$_} } sort keys %c) }
729is prototype(\&t052), undef;
730is eval("t052()"), undef;
aff539aa 731like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 732is eval("t052(222)"), undef;
aff539aa 733like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
734is eval("t052(222, 333)"), "222;333;";
735is eval("t052(222, 333, 456)"), undef;
aff539aa 736like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
737is eval("t052(222, 333, 456, 789)"), "222;333;456=789";
738is eval("t052(222, 333, 456, 789, 987)"), undef;
aff539aa 739like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
740is eval("t052(222, 333, 456, 789, 987, 654)"), "222;333;456=789/987=654";
741is eval("t052(222, 333, 456, 789, 987, 654, 321)"), undef;
aff539aa 742like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
743is eval("t052(222, 333, 456, 789, 987, 654, 321, 111)"),
744 "222;333;321=111/456=789/987=654";
745is $a, 123;
746
747sub t053 ($a, $b, $c, %d) {
748 "$a;$b;$c;".join("/", map { $_."=".$d{$_} } sort keys %d)
749}
750is prototype(\&t053), undef;
751is eval("t053()"), undef;
aff539aa 752like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 753is eval("t053(222)"), undef;
aff539aa 754like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 755is eval("t053(222, 333)"), undef;
aff539aa 756like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
757is eval("t053(222, 333, 444)"), "222;333;444;";
758is eval("t053(222, 333, 444, 456)"), undef;
aff539aa 759like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
760is eval("t053(222, 333, 444, 456, 789)"), "222;333;444;456=789";
761is eval("t053(222, 333, 444, 456, 789, 987)"), undef;
aff539aa 762like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
763is eval("t053(222, 333, 444, 456, 789, 987, 654)"),
764 "222;333;444;456=789/987=654";
765is eval("t053(222, 333, 444, 456, 789, 987, 654, 321)"), 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, 321, 111)"),
768 "222;333;444;321=111/456=789/987=654";
769is $a, 123;
770
771sub t048 ($a = 222, @b) { $a.";".join("/", @b).";".scalar(@b) }
772is prototype(\&t048), undef;
773is eval("t048()"), "222;;0";
774is eval("t048(0)"), "0;;0";
775is eval("t048(456)"), "456;;0";
776is eval("t048(456, 789)"), "456;789;1";
777is eval("t048(456, 789, 987)"), "456;789/987;2";
778is eval("t048(456, 789, 987, 654)"), "456;789/987/654;3";
779is eval("t048(456, 789, 987, 654, 321)"), "456;789/987/654/321;4";
780is eval("t048(456, 789, 987, 654, 321, 111)"), "456;789/987/654/321/111;5";
781is $a, 123;
782
783sub t054 ($a = 222, $b = 333, @c) { "$a;$b;".join("/", @c).";".scalar(@c) }
784is prototype(\&t054), undef;
785is eval("t054()"), "222;333;;0";
786is eval("t054(456)"), "456;333;;0";
787is eval("t054(456, 789)"), "456;789;;0";
788is eval("t054(456, 789, 987)"), "456;789;987;1";
789is eval("t054(456, 789, 987, 654)"), "456;789;987/654;2";
790is eval("t054(456, 789, 987, 654, 321)"), "456;789;987/654/321;3";
791is eval("t054(456, 789, 987, 654, 321, 111)"), "456;789;987/654/321/111;4";
792is $a, 123;
793
794sub t055 ($a = 222, $b = 333, $c = 444, @d) {
795 "$a;$b;$c;".join("/", @d).";".scalar(@d)
796}
797is prototype(\&t055), undef;
798is eval("t055()"), "222;333;444;;0";
799is eval("t055(456)"), "456;333;444;;0";
800is eval("t055(456, 789)"), "456;789;444;;0";
801is eval("t055(456, 789, 987)"), "456;789;987;;0";
802is eval("t055(456, 789, 987, 654)"), "456;789;987;654;1";
803is eval("t055(456, 789, 987, 654, 321)"), "456;789;987;654/321;2";
804is eval("t055(456, 789, 987, 654, 321, 111)"), "456;789;987;654/321/111;3";
805is $a, 123;
806
807sub t050 ($a = 211, %b) { $a.";".join("/", map { $_."=".$b{$_} } sort keys %b) }
808is prototype(\&t050), undef;
809is eval("t050()"), "211;";
810is eval("t050(222)"), "222;";
811is eval("t050(222, 456)"), undef;
aff539aa 812like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
813is eval("t050(222, 456, 789)"), "222;456=789";
814is eval("t050(222, 456, 789, 987)"), undef;
aff539aa 815like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
816is eval("t050(222, 456, 789, 987, 654)"), "222;456=789/987=654";
817is eval("t050(222, 456, 789, 987, 654, 321)"), undef;
aff539aa 818like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
819is eval("t050(222, 456, 789, 987, 654, 321, 111)"),
820 "222;321=111/456=789/987=654";
821is $a, 123;
822
823sub t056 ($a = 211, $b = 311, %c) {
824 "$a;$b;".join("/", map { $_."=".$c{$_} } sort keys %c)
825}
826is prototype(\&t056), undef;
827is eval("t056()"), "211;311;";
828is eval("t056(222)"), "222;311;";
829is eval("t056(222, 333)"), "222;333;";
830is eval("t056(222, 333, 456)"), undef;
aff539aa 831like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
832is eval("t056(222, 333, 456, 789)"), "222;333;456=789";
833is eval("t056(222, 333, 456, 789, 987)"), undef;
aff539aa 834like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
835is eval("t056(222, 333, 456, 789, 987, 654)"), "222;333;456=789/987=654";
836is eval("t056(222, 333, 456, 789, 987, 654, 321)"), undef;
aff539aa 837like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
838is eval("t056(222, 333, 456, 789, 987, 654, 321, 111)"),
839 "222;333;321=111/456=789/987=654";
840is $a, 123;
841
842sub t057 ($a = 211, $b = 311, $c = 411, %d) {
843 "$a;$b;$c;".join("/", map { $_."=".$d{$_} } sort keys %d)
844}
845is prototype(\&t057), undef;
846is eval("t057()"), "211;311;411;";
847is eval("t057(222)"), "222;311;411;";
848is eval("t057(222, 333)"), "222;333;411;";
849is eval("t057(222, 333, 444)"), "222;333;444;";
850is eval("t057(222, 333, 444, 456)"), undef;
aff539aa 851like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
852is eval("t057(222, 333, 444, 456, 789)"), "222;333;444;456=789";
853is eval("t057(222, 333, 444, 456, 789, 987)"), undef;
aff539aa 854like $@, qr#\AOdd name/value argument for subroutine at \(eval \d+\) line 1\.\n\z#;
30d9c59b
Z
855is eval("t057(222, 333, 444, 456, 789, 987, 654)"),
856 "222;333;444;456=789/987=654";
857is eval("t057(222, 333, 444, 456, 789, 987, 654, 321)"), 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, 321, 111)"),
860 "222;333;444;321=111/456=789/987=654";
861is $a, 123;
862
863sub t058 ($a, $b = 333, @c) { "$a;$b;".join("/", @c).";".scalar(@c) }
864is prototype(\&t058), undef;
865is eval("t058()"), undef;
aff539aa 866like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
867is eval("t058(456)"), "456;333;;0";
868is eval("t058(456, 789)"), "456;789;;0";
869is eval("t058(456, 789, 987)"), "456;789;987;1";
870is eval("t058(456, 789, 987, 654)"), "456;789;987/654;2";
871is eval("t058(456, 789, 987, 654, 321)"), "456;789;987/654/321;3";
872is eval("t058(456, 789, 987, 654, 321, 111)"), "456;789;987/654/321/111;4";
873is $a, 123;
874
875eval "#line 8 foo\nsub t059 (\@a, \$b) { }";
876is $@, "Slurpy parameter not last at foo line 8\.\n";
877
878eval "#line 8 foo\nsub t060 (\@a, \$b = 222) { }";
879is $@, "Slurpy parameter not last at foo line 8\.\n";
880
881eval "#line 8 foo\nsub t061 (\@a, \@b) { }";
882is $@, "Slurpy parameter not last at foo line 8\.\n";
883
884eval "#line 8 foo\nsub t062 (\@a, \%b) { }";
885is $@, "Slurpy parameter not last at foo line 8\.\n";
886
887eval "#line 8 foo\nsub t063 (\@, \$b) { }";
888is $@, "Slurpy parameter not last at foo line 8\.\n";
889
890eval "#line 8 foo\nsub t064 (\@, \$b = 222) { }";
891is $@, "Slurpy parameter not last at foo line 8\.\n";
892
893eval "#line 8 foo\nsub t065 (\@, \@b) { }";
894is $@, "Slurpy parameter not last at foo line 8\.\n";
895
896eval "#line 8 foo\nsub t066 (\@, \%b) { }";
897is $@, "Slurpy parameter not last at foo line 8\.\n";
898
899eval "#line 8 foo\nsub t067 (\@a, \$) { }";
900is $@, "Slurpy parameter not last at foo line 8\.\n";
901
902eval "#line 8 foo\nsub t068 (\@a, \$ = 222) { }";
903is $@, "Slurpy parameter not last at foo line 8\.\n";
904
905eval "#line 8 foo\nsub t069 (\@a, \@) { }";
906is $@, "Slurpy parameter not last at foo line 8\.\n";
907
908eval "#line 8 foo\nsub t070 (\@a, \%) { }";
909is $@, "Slurpy parameter not last at foo line 8\.\n";
910
911eval "#line 8 foo\nsub t071 (\@, \$) { }";
912is $@, "Slurpy parameter not last at foo line 8\.\n";
913
914eval "#line 8 foo\nsub t072 (\@, \$ = 222) { }";
915is $@, "Slurpy parameter not last at foo line 8\.\n";
916
917eval "#line 8 foo\nsub t073 (\@, \@) { }";
918is $@, "Slurpy parameter not last at foo line 8\.\n";
919
920eval "#line 8 foo\nsub t074 (\@, \%) { }";
921is $@, "Slurpy parameter not last at foo line 8\.\n";
922
923eval "#line 8 foo\nsub t075 (\%a, \$b) { }";
924is $@, "Slurpy parameter not last at foo line 8\.\n";
925
926eval "#line 8 foo\nsub t076 (\%, \$b) { }";
927is $@, "Slurpy parameter not last at foo line 8\.\n";
928
929eval "#line 8 foo\nsub t077 (\$a, \@b, \$c) { }";
930is $@, "Slurpy parameter not last at foo line 8\.\n";
931
932eval "#line 8 foo\nsub t078 (\$a, \%b, \$c) { }";
933is $@, "Slurpy parameter not last at foo line 8\.\n";
934
935eval "#line 8 foo\nsub t079 (\$a, \@b, \$c, \$d) { }";
936is $@, "Slurpy parameter not last at foo line 8\.\n";
937
938sub t080 ($a,,, $b) { $a.$b }
939is prototype(\&t080), undef;
940is eval("t080()"), undef;
aff539aa 941like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 942is eval("t080(456)"), undef;
aff539aa 943like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
944is eval("t080(456, 789)"), "456789";
945is eval("t080(456, 789, 987)"), undef;
aff539aa 946like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 947is eval("t080(456, 789, 987, 654)"), undef;
aff539aa 948like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
949is $a, 123;
950
951sub t081 ($a, $b,,) { $a.$b }
952is prototype(\&t081), undef;
953is eval("t081()"), undef;
aff539aa 954like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 955is eval("t081(456)"), undef;
aff539aa 956like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
957is eval("t081(456, 789)"), "456789";
958is eval("t081(456, 789, 987)"), undef;
aff539aa 959like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 960is eval("t081(456, 789, 987, 654)"), undef;
aff539aa 961like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
962is $a, 123;
963
964eval "#line 8 foo\nsub t082 (, \$a) { }";
965like $@, qr/\AParse error at foo line 8\.\n/;
966
967eval "#line 8 foo\nsub t083 (,) { }";
968like $@, qr/\AParse error at foo line 8\.\n/;
969
970sub t084($a,$b){ $a.$b }
971is prototype(\&t084), undef;
972is eval("t084()"), undef;
aff539aa 973like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 974is eval("t084(456)"), undef;
aff539aa 975like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
976is eval("t084(456, 789)"), "456789";
977is eval("t084(456, 789, 987)"), undef;
aff539aa 978like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 979is eval("t084(456, 789, 987, 654)"), undef;
aff539aa 980like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
981is $a, 123;
982
983sub t085
984 (
985 $
986 a
987 ,
988 ,
989 $
990 b
991 =
992 333
993 ,
994 ,
995 )
996 { $a.$b }
997is prototype(\&t085), undef;
998is eval("t085()"), undef;
aff539aa 999like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1000is eval("t085(456)"), "456333";
1001is eval("t085(456, 789)"), "456789";
1002is eval("t085(456, 789, 987)"), undef;
aff539aa 1003like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1004is eval("t085(456, 789, 987, 654)"), undef;
aff539aa 1005like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1006is $a, 123;
1007
1008sub t086
1009 ( #foo)))
1010 $ #foo)))
1011 a #foo)))
1012 , #foo)))
1013 , #foo)))
1014 $ #foo)))
1015 b #foo)))
1016 = #foo)))
1017 333 #foo)))
1018 , #foo)))
1019 , #foo)))
1020 ) #foo)))
1021 { $a.$b }
1022is prototype(\&t086), undef;
1023is eval("t086()"), undef;
aff539aa 1024like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1025is eval("t086(456)"), "456333";
1026is eval("t086(456, 789)"), "456789";
1027is eval("t086(456, 789, 987)"), undef;
aff539aa 1028like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1029is eval("t086(456, 789, 987, 654)"), undef;
aff539aa 1030like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1031is $a, 123;
1032
1033sub t087
1034 (#foo)))
1035 $ #foo)))
1036 a#foo)))
1037 ,#foo)))
1038 ,#foo)))
1039 $ #foo)))
1040 b#foo)))
1041 =#foo)))
1042 333#foo)))
1043 ,#foo)))
1044 ,#foo)))
1045 )#foo)))
1046 { $a.$b }
1047is prototype(\&t087), undef;
1048is eval("t087()"), undef;
aff539aa 1049like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1050is eval("t087(456)"), "456333";
1051is eval("t087(456, 789)"), "456789";
1052is eval("t087(456, 789, 987)"), undef;
aff539aa 1053like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1054is eval("t087(456, 789, 987, 654)"), undef;
aff539aa 1055like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1056is $a, 123;
1057
1058eval "#line 8 foo\nsub t088 (\$ #foo\na) { }";
1059is $@, "";
1060
1061eval "#line 8 foo\nsub t089 (\$#foo\na) { }";
1062like $@, qr/\AParse error at foo line 8\.\n/;
1063
1064eval "#line 8 foo\nsub t090 (\@ #foo\na) { }";
1065is $@, "";
1066
1067eval "#line 8 foo\nsub t091 (\@#foo\na) { }";
1068like $@, qr/\AParse error at foo line 8\.\n/;
1069
1070eval "#line 8 foo\nsub t092 (\% #foo\na) { }";
1071is $@, "";
1072
1073eval "#line 8 foo\nsub t093 (\%#foo\na) { }";
1074like $@, qr/\AParse error at foo line 8\.\n/;
1075
1076eval "#line 8 foo\nsub t094 (123) { }";
1077like $@, qr/\AParse error at foo line 8\.\n/;
1078
1079eval "#line 8 foo\nsub t095 (\$a, 123) { }";
1080like $@, qr/\AParse error at foo line 8\.\n/;
1081
1082eval "#line 8 foo\nsub t096 (\$a 123) { }";
1083like $@, qr/\AParse error at foo line 8\.\n/;
1084
1085eval "#line 8 foo\nsub t097 (\$a { }) { }";
1086like $@, qr/\AParse error at foo line 8\.\n/;
1087
1088eval "#line 8 foo\nsub t098 (\$a; \$b) { }";
1089like $@, qr/\AParse error at foo line 8\.\n/;
1090
1091eval "#line 8 foo\nsub t099 (\$\$) { }";
1092like $@, qr/\AParse error at foo line 8\.\n/;
1093
30d9c59b
Z
1094eval "#line 8 foo\nsub t101 (\@_) { }";
1095like $@, qr/\ACan't use global \@_ in "my" at foo line 8/;
1096
1097eval "#line 8 foo\nsub t102 (\%_) { }";
1098like $@, qr/\ACan't use global \%_ in "my" at foo line 8/;
1099
1100my $t103 = sub ($a) { $a || "z" };
1101is prototype($t103), undef;
1102is eval("\$t103->()"), undef;
aff539aa 1103like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1104is eval("\$t103->(0)"), "z";
1105is eval("\$t103->(456)"), 456;
1106is eval("\$t103->(456, 789)"), undef;
aff539aa 1107like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1108is eval("\$t103->(456, 789, 987)"), undef;
aff539aa 1109like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1110is $a, 123;
1111
abcf453d 1112my $t118 = sub ($a) :prototype($) { $a || "z" };
30d9c59b
Z
1113is prototype($t118), "\$";
1114is eval("\$t118->()"), undef;
aff539aa 1115like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1116is eval("\$t118->(0)"), "z";
1117is eval("\$t118->(456)"), 456;
1118is eval("\$t118->(456, 789)"), undef;
aff539aa 1119like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1120is eval("\$t118->(456, 789, 987)"), undef;
aff539aa 1121like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1122is $a, 123;
1123
1124sub t033 ($a = sub ($a) { $a."z" }) { $a->("a")."y" }
1125is prototype(\&t033), undef;
1126is eval("t033()"), "azy";
1127is eval("t033(sub { \"x\".\$_[0].\"x\" })"), "xaxy";
1128is eval("t033(sub { \"x\".\$_[0].\"x\" }, 789)"), undef;
aff539aa 1129like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1130is $a, 123;
1131
863e3089
Z
1132sub t133 ($a = sub ($a = 222) { $a."z" }) { $a->()."/".$a->("a") }
1133is prototype(\&t133), undef;
1134is eval("t133()"), "222z/az";
1135is eval("t133(sub { \"x\".(\$_[0] // \"u\").\"x\" })"), "xux/xax";
1136is eval("t133(sub { \"x\".(\$_[0] // \"u\").\"x\" }, 789)"), undef;
aff539aa 1137like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1138is $a, 123;
1139
1140sub t134 ($a = sub ($a, $t = sub { $_[0]."p" }) { $t->($a)."z" }) {
1141 $a->("a")."/".$a->("b", sub { $_[0]."q" } )
1142}
1143is prototype(\&t134), undef;
1144is eval("t134()"), "apz/bqz";
1145is eval("t134(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" })"),
1146 "xax/xbqx";
1147is eval("t134(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" }, 789)"),
1148 undef;
aff539aa 1149like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1150is $a, 123;
1151
1152sub t135 ($a = sub ($a, $t = sub ($p) { $p."p" }) { $t->($a)."z" }) {
1153 $a->("a")."/".$a->("b", sub { $_[0]."q" } )
1154}
1155is prototype(\&t135), undef;
1156is eval("t135()"), "apz/bqz";
1157is eval("t135(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" })"),
1158 "xax/xbqx";
1159is eval("t135(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" }, 789)"),
1160 undef;
aff539aa 1161like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1162is $a, 123;
1163
1164sub t132 (
1165 $a = sub ($a, $t = sub ($p = 222) { $p."p" }) { $t->($a)."z".$t->() },
1166) {
1167 $a->("a")."/".$a->("b", sub { ($_[0] // "u")."q" } )
1168}
1169is prototype(\&t132), undef;
1170is eval("t132()"), "apz222p/bqzuq";
1171is eval("t132(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" })"),
1172 "xax/xbqx";
1173is eval("t132(sub { \"x\".(\$_[1] // sub{\$_[0]})->(\$_[0]).\"x\" }, 789)"),
1174 undef;
aff539aa 1175like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
863e3089
Z
1176is $a, 123;
1177
abcf453d 1178sub t104($a) :method { $a || "z" }
30d9c59b
Z
1179is prototype(\&t104), undef;
1180is eval("t104()"), undef;
aff539aa 1181like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1182is eval("t104(0)"), "z";
1183is eval("t104(456)"), 456;
1184is eval("t104(456, 789)"), undef;
aff539aa 1185like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1186is eval("t104(456, 789, 987)"), undef;
aff539aa 1187like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1188is $a, 123;
1189
abcf453d 1190sub t105($a) :prototype($) { $a || "z" }
30d9c59b
Z
1191is prototype(\&t105), "\$";
1192is eval("t105()"), undef;
1193like $@, qr/\ANot enough arguments for main::t105 /;
1194is eval("t105(0)"), "z";
1195is eval("t105(456)"), 456;
1196is eval("t105(456, 789)"), undef;
aff539aa 1197like $@, qr/\AToo many arguments for main::t105 at \(eval \d+\) line 1, near/;
30d9c59b 1198is eval("t105(456, 789, 987)"), undef;
aff539aa 1199like $@, qr/\AToo many arguments for main::t105 at \(eval \d+\) line 1, near/;
30d9c59b
Z
1200is $a, 123;
1201
abcf453d 1202sub t106($a) :prototype(@) { $a || "z" }
30d9c59b
Z
1203is prototype(\&t106), "\@";
1204is eval("t106()"), undef;
aff539aa 1205like $@, qr/\AToo few arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1206is eval("t106(0)"), "z";
1207is eval("t106(456)"), 456;
1208is eval("t106(456, 789)"), undef;
aff539aa 1209like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b 1210is eval("t106(456, 789, 987)"), undef;
aff539aa 1211like $@, qr/\AToo many arguments for subroutine at \(eval \d+\) line 1\.\n\z/;
30d9c59b
Z
1212is $a, 123;
1213
abcf453d 1214eval "#line 8 foo\nsub t107 :method (\$a) { }";
30d9c59b
Z
1215isnt $@, "";
1216
abcf453d 1217eval "#line 8 foo\nsub t108 :prototype(\$) (\$a) { }";
30d9c59b
Z
1218isnt $@, "";
1219
1220sub t109 { }
1221is prototype(\&t109), undef;
1222is scalar(@{[ t109() ]}), 0;
1223is scalar(t109()), undef;
1224
1225sub t110 () { }
1226is prototype(\&t110), undef;
1227is scalar(@{[ t110() ]}), 0;
1228is scalar(t110()), undef;
1229
1230sub t111 ($a) { }
1231is prototype(\&t111), undef;
1232is scalar(@{[ t111(222) ]}), 0;
1233is scalar(t111(222)), undef;
1234
1235sub t112 ($) { }
1236is prototype(\&t112), undef;
1237is scalar(@{[ t112(222) ]}), 0;
1238is scalar(t112(222)), undef;
1239
1240sub t114 ($a = undef) { }
1241is prototype(\&t114), undef;
1242is scalar(@{[ t114() ]}), 0;
1243is scalar(t114()), undef;
1244is scalar(@{[ t114(333) ]}), 0;
1245is scalar(t114(333)), undef;
1246
1247sub t113 ($a = 222) { }
1248is prototype(\&t113), undef;
1249is scalar(@{[ t113() ]}), 0;
1250is scalar(t113()), undef;
1251is scalar(@{[ t113(333) ]}), 0;
1252is scalar(t113(333)), undef;
1253
1254sub t115 ($a = do { $z++; 222 }) { }
1255is prototype(\&t115), undef;
1256$z = 0;
1257is scalar(@{[ t115() ]}), 0;
1258is $z, 1;
1259is scalar(t115()), undef;
1260is $z, 2;
1261is scalar(@{[ t115(333) ]}), 0;
1262is scalar(t115(333)), undef;
1263is $z, 2;
1264
1265sub t116 (@a) { }
1266is prototype(\&t116), undef;
1267is scalar(@{[ t116() ]}), 0;
1268is scalar(t116()), undef;
1269is scalar(@{[ t116(333) ]}), 0;
1270is scalar(t116(333)), undef;
1271
1272sub t117 (%a) { }
1273is prototype(\&t117), undef;
1274is scalar(@{[ t117() ]}), 0;
1275is scalar(t117()), undef;
1276is scalar(@{[ t117(333, 444) ]}), 0;
1277is scalar(t117(333, 444)), undef;
1278
1ccc3f31
FC
1279use File::Spec::Functions;
1280my $keywords_file = catfile(updir,'regen','keywords.pl');
1281open my $kh, $keywords_file
1282 or die "$0 cannot open $keywords_file: $!";
1283while(<$kh>) {
1284 if (m?__END__?..${\0} and /^[+-]/) {
1285 chomp(my $word = $');
1286 # $y should be an error after $x=foo. The exact error we get may
1287 # differ if this is __END__ or s or some other special keyword.
1288 eval 'sub ($x = ' . $word . ', $y) {}';
1289 local $::TODO = 'does not work yet'
1290 if $word =~ /^(?:chmod|chown|die|exec|glob|kill|mkdir|print
1291 |printf|return|reverse|select|setpgrp|sort|split
1292 |system|unlink|utime|warn)\z/x;
1293 isnt $@, "", "$word does not swallow trailing comma";
1294 }
1295}
1296
1297done_testing;
1298
30d9c59b 12991;