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