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