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