This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
subroutine signatures
[perl5.git] / t / op / signatures.t
CommitLineData
30d9c59b
Z
1#!perl
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8plan 768;
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
272sub t037 ($a = 222, $b = $a."x") { "$a/$b" }
273is prototype(\&t037), undef;
274is eval("t037()"), "222/222x";
275is eval("t037(0)"), "0/0x";
276is eval("t037(456)"), "456/456x";
277is eval("t037(456, 789)"), "456/789";
278is eval("t037(456, 789, 987)"), undef;
279like $@, qr/\AToo many arguments for subroutine at/;
280is $a, 123;
281
282eval "#line 8 foo\nsub t024 (\$a =) { }";
283is $@, "Optional parameter lacks default expression at foo line 8\.\n";
284
285sub t025 ($ = undef) { $a // "z" }
286is prototype(\&t025), undef;
287is eval("t025()"), 123;
288is eval("t025(0)"), 123;
289is eval("t025(456)"), 123;
290is eval("t025(456, 789)"), undef;
291like $@, qr/\AToo many arguments for subroutine at/;
292is eval("t025(456, 789, 987)"), undef;
293like $@, qr/\AToo many arguments for subroutine at/;
294is eval("t025(456, 789, 987, 654)"), undef;
295like $@, qr/\AToo many arguments for subroutine at/;
296is $a, 123;
297
298sub t026 ($ = 222) { $a // "z" }
299is prototype(\&t026), undef;
300is eval("t026()"), 123;
301is eval("t026(0)"), 123;
302is eval("t026(456)"), 123;
303is eval("t026(456, 789)"), undef;
304like $@, qr/\AToo many arguments for subroutine at/;
305is eval("t026(456, 789, 987)"), undef;
306like $@, qr/\AToo many arguments for subroutine at/;
307is eval("t026(456, 789, 987, 654)"), undef;
308like $@, qr/\AToo many arguments for subroutine at/;
309is $a, 123;
310
311sub t032 ($ = do { $z++; 222 }) { $a // "z" }
312$z = 0;
313is prototype(\&t032), undef;
314is eval("t032()"), 123;
315is $z, 1;
316is eval("t032(0)"), 123;
317is eval("t032(456)"), 123;
318is eval("t032(456, 789)"), undef;
319like $@, qr/\AToo many arguments for subroutine at/;
320is eval("t032(456, 789, 987)"), undef;
321like $@, qr/\AToo many arguments for subroutine at/;
322is eval("t032(456, 789, 987, 654)"), undef;
323like $@, qr/\AToo many arguments for subroutine at/;
324is $z, 1;
325is $a, 123;
326
327sub t027 ($ =) { $a // "z" }
328is prototype(\&t027), undef;
329is eval("t027()"), 123;
330is eval("t027(0)"), 123;
331is eval("t027(456)"), 123;
332is eval("t027(456, 789)"), undef;
333like $@, qr/\AToo many arguments for subroutine at/;
334is eval("t027(456, 789, 987)"), undef;
335like $@, qr/\AToo many arguments for subroutine at/;
336is eval("t027(456, 789, 987, 654)"), undef;
337like $@, qr/\AToo many arguments for subroutine at/;
338is $a, 123;
339
340sub t119 ($ =, $a = 333) { $a // "z" }
341is prototype(\&t119), undef;
342is eval("t119()"), 333;
343is eval("t119(0)"), 333;
344is eval("t119(456)"), 333;
345is eval("t119(456, 789)"), 789;
346is eval("t119(456, 789, 987)"), undef;
347like $@, qr/\AToo many arguments for subroutine at/;
348is eval("t119(456, 789, 987, 654)"), undef;
349like $@, qr/\AToo many arguments for subroutine at/;
350is $a, 123;
351
352sub t028 ($a, $b = 333) { "$a/$b" }
353is prototype(\&t028), undef;
354is eval("t028()"), undef;
355like $@, qr/\AToo few arguments for subroutine at/;
356is eval("t028(0)"), "0/333";
357is eval("t028(456)"), "456/333";
358is eval("t028(456, 789)"), "456/789";
359is eval("t028(456, 789, 987)"), undef;
360like $@, qr/\AToo many arguments for subroutine at/;
361is $a, 123;
362
363sub t045 ($a, $ = 333) { "$a/" }
364is prototype(\&t045), undef;
365is eval("t045()"), undef;
366like $@, qr/\AToo few arguments for subroutine at/;
367is eval("t045(0)"), "0/";
368is eval("t045(456)"), "456/";
369is eval("t045(456, 789)"), "456/";
370is eval("t045(456, 789, 987)"), undef;
371like $@, qr/\AToo many arguments for subroutine at/;
372is $a, 123;
373
374sub t046 ($, $b = 333) { "$a/$b" }
375is prototype(\&t046), undef;
376is eval("t046()"), undef;
377like $@, qr/\AToo few arguments for subroutine at/;
378is eval("t046(0)"), "123/333";
379is eval("t046(456)"), "123/333";
380is eval("t046(456, 789)"), "123/789";
381is eval("t046(456, 789, 987)"), undef;
382like $@, qr/\AToo many arguments for subroutine at/;
383is $a, 123;
384
385sub t047 ($, $ = 333) { "$a/" }
386is prototype(\&t047), undef;
387is eval("t047()"), undef;
388like $@, qr/\AToo few arguments for subroutine at/;
389is eval("t047(0)"), "123/";
390is eval("t047(456)"), "123/";
391is eval("t047(456, 789)"), "123/";
392is eval("t047(456, 789, 987)"), undef;
393like $@, qr/\AToo many arguments for subroutine at/;
394is $a, 123;
395
396sub t029 ($a, $b, $c = 222, $d = 333) { "$a/$b/$c/$d" }
397is prototype(\&t029), undef;
398is eval("t029()"), undef;
399like $@, qr/\AToo few arguments for subroutine at/;
400is eval("t029(0)"), undef;
401like $@, qr/\AToo few arguments for subroutine at/;
402is eval("t029(456)"), undef;
403like $@, qr/\AToo few arguments for subroutine at/;
404is eval("t029(456, 789)"), "456/789/222/333";
405is eval("t029(456, 789, 987)"), "456/789/987/333";
406is eval("t029(456, 789, 987, 654)"), "456/789/987/654";
407is eval("t029(456, 789, 987, 654, 321)"), undef;
408like $@, qr/\AToo many arguments for subroutine at/;
409is eval("t029(456, 789, 987, 654, 321, 111)"), undef;
410like $@, qr/\AToo many arguments for subroutine at/;
411is $a, 123;
412
413sub t038 ($a, $b = $a."x") { "$a/$b" }
414is prototype(\&t038), undef;
415is eval("t038()"), undef;
416like $@, qr/\AToo few arguments for subroutine at/;
417is eval("t038(0)"), "0/0x";
418is eval("t038(456)"), "456/456x";
419is eval("t038(456, 789)"), "456/789";
420is eval("t038(456, 789, 987)"), undef;
421like $@, qr/\AToo many arguments for subroutine at/;
422is $a, 123;
423
424eval "#line 8 foo\nsub t030 (\$a = 222, \$b) { }";
425is $@, "Mandatory parameter follows optional parameter at foo line 8\.\n";
426
427eval "#line 8 foo\nsub t031 (\$a = 222, \$b = 333, \$c, \$d) { }";
428is $@, "Mandatory parameter follows optional parameter at foo line 8\.\n";
429
430sub t034 (@abc) { join("/", @abc).";".scalar(@abc) }
431is prototype(\&t034), undef;
432is eval("t034()"), ";0";
433is eval("t034(0)"), "0;1";
434is eval("t034(456)"), "456;1";
435is eval("t034(456, 789)"), "456/789;2";
436is eval("t034(456, 789, 987)"), "456/789/987;3";
437is eval("t034(456, 789, 987, 654)"), "456/789/987/654;4";
438is eval("t034(456, 789, 987, 654, 321)"), "456/789/987/654/321;5";
439is eval("t034(456, 789, 987, 654, 321, 111)"), "456/789/987/654/321/111;6";
440is $a, 123;
441
442sub t035 (@) { $a }
443is prototype(\&t035), undef;
444is eval("t035()"), 123;
445is eval("t035(0)"), 123;
446is eval("t035(456)"), 123;
447is eval("t035(456, 789)"), 123;
448is eval("t035(456, 789, 987)"), 123;
449is eval("t035(456, 789, 987, 654)"), 123;
450is eval("t035(456, 789, 987, 654, 321)"), 123;
451is eval("t035(456, 789, 987, 654, 321, 111)"), 123;
452is $a, 123;
453
454sub t039 (%abc) { join("/", map { $_."=".$abc{$_} } sort keys %abc) }
455is prototype(\&t039), undef;
456is eval("t039()"), "";
457is eval("t039(0)"), undef;
458like $@, qr#\AOdd name/value argument for subroutine at#;
459is eval("t039(456)"), undef;
460like $@, qr#\AOdd name/value argument for subroutine at#;
461is eval("t039(456, 789)"), "456=789";
462is eval("t039(456, 789, 987)"), undef;
463like $@, qr#\AOdd name/value argument for subroutine at#;
464is eval("t039(456, 789, 987, 654)"), "456=789/987=654";
465is eval("t039(456, 789, 987, 654, 321)"), undef;
466like $@, qr#\AOdd name/value argument for subroutine at#;
467is eval("t039(456, 789, 987, 654, 321, 111)"), "321=111/456=789/987=654";
468is $a, 123;
469
470sub t040 (%) { $a }
471is prototype(\&t040), undef;
472is eval("t040()"), 123;
473is eval("t040(0)"), undef;
474like $@, qr#\AOdd name/value argument for subroutine at#;
475is eval("t040(456)"), undef;
476like $@, qr#\AOdd name/value argument for subroutine at#;
477is eval("t040(456, 789)"), 123;
478is eval("t040(456, 789, 987)"), undef;
479like $@, qr#\AOdd name/value argument for subroutine at#;
480is eval("t040(456, 789, 987, 654)"), 123;
481is eval("t040(456, 789, 987, 654, 321)"), undef;
482like $@, qr#\AOdd name/value argument for subroutine at#;
483is eval("t040(456, 789, 987, 654, 321, 111)"), 123;
484is $a, 123;
485
486sub t041 ($a, @b) { $a.";".join("/", @b) }
487is prototype(\&t041), undef;
488is eval("t041()"), undef;
489like $@, qr/\AToo few arguments for subroutine at/;
490is eval("t041(0)"), "0;";
491is eval("t041(456)"), "456;";
492is eval("t041(456, 789)"), "456;789";
493is eval("t041(456, 789, 987)"), "456;789/987";
494is eval("t041(456, 789, 987, 654)"), "456;789/987/654";
495is eval("t041(456, 789, 987, 654, 321)"), "456;789/987/654/321";
496is eval("t041(456, 789, 987, 654, 321, 111)"), "456;789/987/654/321/111";
497is $a, 123;
498
499sub t042 ($a, @) { $a.";" }
500is prototype(\&t042), undef;
501is eval("t042()"), undef;
502like $@, qr/\AToo few arguments for subroutine at/;
503is eval("t042(0)"), "0;";
504is eval("t042(456)"), "456;";
505is eval("t042(456, 789)"), "456;";
506is eval("t042(456, 789, 987)"), "456;";
507is eval("t042(456, 789, 987, 654)"), "456;";
508is eval("t042(456, 789, 987, 654, 321)"), "456;";
509is eval("t042(456, 789, 987, 654, 321, 111)"), "456;";
510is $a, 123;
511
512sub t043 ($, @b) { $a.";".join("/", @b) }
513is prototype(\&t043), undef;
514is eval("t043()"), undef;
515like $@, qr/\AToo few arguments for subroutine at/;
516is eval("t043(0)"), "123;";
517is eval("t043(456)"), "123;";
518is eval("t043(456, 789)"), "123;789";
519is eval("t043(456, 789, 987)"), "123;789/987";
520is eval("t043(456, 789, 987, 654)"), "123;789/987/654";
521is eval("t043(456, 789, 987, 654, 321)"), "123;789/987/654/321";
522is eval("t043(456, 789, 987, 654, 321, 111)"), "123;789/987/654/321/111";
523is $a, 123;
524
525sub t044 ($, @) { $a.";" }
526is prototype(\&t044), undef;
527is eval("t044()"), undef;
528like $@, qr/\AToo few arguments for subroutine at/;
529is eval("t044(0)"), "123;";
530is eval("t044(456)"), "123;";
531is eval("t044(456, 789)"), "123;";
532is eval("t044(456, 789, 987)"), "123;";
533is eval("t044(456, 789, 987, 654)"), "123;";
534is eval("t044(456, 789, 987, 654, 321)"), "123;";
535is eval("t044(456, 789, 987, 654, 321, 111)"), "123;";
536is $a, 123;
537
538sub t049 ($a, %b) { $a.";".join("/", map { $_."=".$b{$_} } sort keys %b) }
539is prototype(\&t049), undef;
540is eval("t049()"), undef;
541like $@, qr/\AToo few arguments for subroutine at/;
542is eval("t049(222)"), "222;";
543is eval("t049(222, 456)"), undef;
544like $@, qr#\AOdd name/value argument for subroutine at#;
545is eval("t049(222, 456, 789)"), "222;456=789";
546is eval("t049(222, 456, 789, 987)"), undef;
547like $@, qr#\AOdd name/value argument for subroutine at#;
548is eval("t049(222, 456, 789, 987, 654)"), "222;456=789/987=654";
549is eval("t049(222, 456, 789, 987, 654, 321)"), undef;
550like $@, qr#\AOdd name/value argument for subroutine at#;
551is eval("t049(222, 456, 789, 987, 654, 321, 111)"),
552 "222;321=111/456=789/987=654";
553is $a, 123;
554
555sub t051 ($a, $b, $c, @d) { "$a;$b;$c;".join("/", @d).";".scalar(@d) }
556is prototype(\&t051), undef;
557is eval("t051()"), undef;
558like $@, qr/\AToo few arguments for subroutine at/;
559is eval("t051(456)"), undef;
560like $@, qr/\AToo few arguments for subroutine at/;
561is eval("t051(456, 789)"), undef;
562like $@, qr/\AToo few arguments for subroutine at/;
563is eval("t051(456, 789, 987)"), "456;789;987;;0";
564is eval("t051(456, 789, 987, 654)"), "456;789;987;654;1";
565is eval("t051(456, 789, 987, 654, 321)"), "456;789;987;654/321;2";
566is eval("t051(456, 789, 987, 654, 321, 111)"), "456;789;987;654/321/111;3";
567is $a, 123;
568
569sub t052 ($a, $b, %c) { "$a;$b;".join("/", map { $_."=".$c{$_} } sort keys %c) }
570is prototype(\&t052), undef;
571is eval("t052()"), undef;
572like $@, qr/\AToo few arguments for subroutine at/;
573is eval("t052(222)"), undef;
574like $@, qr/\AToo few arguments for subroutine at/;
575is eval("t052(222, 333)"), "222;333;";
576is eval("t052(222, 333, 456)"), undef;
577like $@, qr#\AOdd name/value argument for subroutine at#;
578is eval("t052(222, 333, 456, 789)"), "222;333;456=789";
579is eval("t052(222, 333, 456, 789, 987)"), undef;
580like $@, qr#\AOdd name/value argument for subroutine at#;
581is eval("t052(222, 333, 456, 789, 987, 654)"), "222;333;456=789/987=654";
582is eval("t052(222, 333, 456, 789, 987, 654, 321)"), undef;
583like $@, qr#\AOdd name/value argument for subroutine at#;
584is eval("t052(222, 333, 456, 789, 987, 654, 321, 111)"),
585 "222;333;321=111/456=789/987=654";
586is $a, 123;
587
588sub t053 ($a, $b, $c, %d) {
589 "$a;$b;$c;".join("/", map { $_."=".$d{$_} } sort keys %d)
590}
591is prototype(\&t053), undef;
592is eval("t053()"), undef;
593like $@, qr/\AToo few arguments for subroutine at/;
594is eval("t053(222)"), undef;
595like $@, qr/\AToo few arguments for subroutine at/;
596is eval("t053(222, 333)"), undef;
597like $@, qr/\AToo few arguments for subroutine at/;
598is eval("t053(222, 333, 444)"), "222;333;444;";
599is eval("t053(222, 333, 444, 456)"), undef;
600like $@, qr#\AOdd name/value argument for subroutine at#;
601is eval("t053(222, 333, 444, 456, 789)"), "222;333;444;456=789";
602is eval("t053(222, 333, 444, 456, 789, 987)"), undef;
603like $@, qr#\AOdd name/value argument for subroutine at#;
604is eval("t053(222, 333, 444, 456, 789, 987, 654)"),
605 "222;333;444;456=789/987=654";
606is eval("t053(222, 333, 444, 456, 789, 987, 654, 321)"), undef;
607like $@, qr#\AOdd name/value argument for subroutine at#;
608is eval("t053(222, 333, 444, 456, 789, 987, 654, 321, 111)"),
609 "222;333;444;321=111/456=789/987=654";
610is $a, 123;
611
612sub t048 ($a = 222, @b) { $a.";".join("/", @b).";".scalar(@b) }
613is prototype(\&t048), undef;
614is eval("t048()"), "222;;0";
615is eval("t048(0)"), "0;;0";
616is eval("t048(456)"), "456;;0";
617is eval("t048(456, 789)"), "456;789;1";
618is eval("t048(456, 789, 987)"), "456;789/987;2";
619is eval("t048(456, 789, 987, 654)"), "456;789/987/654;3";
620is eval("t048(456, 789, 987, 654, 321)"), "456;789/987/654/321;4";
621is eval("t048(456, 789, 987, 654, 321, 111)"), "456;789/987/654/321/111;5";
622is $a, 123;
623
624sub t054 ($a = 222, $b = 333, @c) { "$a;$b;".join("/", @c).";".scalar(@c) }
625is prototype(\&t054), undef;
626is eval("t054()"), "222;333;;0";
627is eval("t054(456)"), "456;333;;0";
628is eval("t054(456, 789)"), "456;789;;0";
629is eval("t054(456, 789, 987)"), "456;789;987;1";
630is eval("t054(456, 789, 987, 654)"), "456;789;987/654;2";
631is eval("t054(456, 789, 987, 654, 321)"), "456;789;987/654/321;3";
632is eval("t054(456, 789, 987, 654, 321, 111)"), "456;789;987/654/321/111;4";
633is $a, 123;
634
635sub t055 ($a = 222, $b = 333, $c = 444, @d) {
636 "$a;$b;$c;".join("/", @d).";".scalar(@d)
637}
638is prototype(\&t055), undef;
639is eval("t055()"), "222;333;444;;0";
640is eval("t055(456)"), "456;333;444;;0";
641is eval("t055(456, 789)"), "456;789;444;;0";
642is eval("t055(456, 789, 987)"), "456;789;987;;0";
643is eval("t055(456, 789, 987, 654)"), "456;789;987;654;1";
644is eval("t055(456, 789, 987, 654, 321)"), "456;789;987;654/321;2";
645is eval("t055(456, 789, 987, 654, 321, 111)"), "456;789;987;654/321/111;3";
646is $a, 123;
647
648sub t050 ($a = 211, %b) { $a.";".join("/", map { $_."=".$b{$_} } sort keys %b) }
649is prototype(\&t050), undef;
650is eval("t050()"), "211;";
651is eval("t050(222)"), "222;";
652is eval("t050(222, 456)"), undef;
653like $@, qr#\AOdd name/value argument for subroutine at#;
654is eval("t050(222, 456, 789)"), "222;456=789";
655is eval("t050(222, 456, 789, 987)"), undef;
656like $@, qr#\AOdd name/value argument for subroutine at#;
657is eval("t050(222, 456, 789, 987, 654)"), "222;456=789/987=654";
658is eval("t050(222, 456, 789, 987, 654, 321)"), undef;
659like $@, qr#\AOdd name/value argument for subroutine at#;
660is eval("t050(222, 456, 789, 987, 654, 321, 111)"),
661 "222;321=111/456=789/987=654";
662is $a, 123;
663
664sub t056 ($a = 211, $b = 311, %c) {
665 "$a;$b;".join("/", map { $_."=".$c{$_} } sort keys %c)
666}
667is prototype(\&t056), undef;
668is eval("t056()"), "211;311;";
669is eval("t056(222)"), "222;311;";
670is eval("t056(222, 333)"), "222;333;";
671is eval("t056(222, 333, 456)"), undef;
672like $@, qr#\AOdd name/value argument for subroutine at#;
673is eval("t056(222, 333, 456, 789)"), "222;333;456=789";
674is eval("t056(222, 333, 456, 789, 987)"), undef;
675like $@, qr#\AOdd name/value argument for subroutine at#;
676is eval("t056(222, 333, 456, 789, 987, 654)"), "222;333;456=789/987=654";
677is eval("t056(222, 333, 456, 789, 987, 654, 321)"), undef;
678like $@, qr#\AOdd name/value argument for subroutine at#;
679is eval("t056(222, 333, 456, 789, 987, 654, 321, 111)"),
680 "222;333;321=111/456=789/987=654";
681is $a, 123;
682
683sub t057 ($a = 211, $b = 311, $c = 411, %d) {
684 "$a;$b;$c;".join("/", map { $_."=".$d{$_} } sort keys %d)
685}
686is prototype(\&t057), undef;
687is eval("t057()"), "211;311;411;";
688is eval("t057(222)"), "222;311;411;";
689is eval("t057(222, 333)"), "222;333;411;";
690is eval("t057(222, 333, 444)"), "222;333;444;";
691is eval("t057(222, 333, 444, 456)"), undef;
692like $@, qr#\AOdd name/value argument for subroutine at#;
693is eval("t057(222, 333, 444, 456, 789)"), "222;333;444;456=789";
694is eval("t057(222, 333, 444, 456, 789, 987)"), undef;
695like $@, qr#\AOdd name/value argument for subroutine at#;
696is eval("t057(222, 333, 444, 456, 789, 987, 654)"),
697 "222;333;444;456=789/987=654";
698is eval("t057(222, 333, 444, 456, 789, 987, 654, 321)"), undef;
699like $@, qr#\AOdd name/value argument for subroutine at#;
700is eval("t057(222, 333, 444, 456, 789, 987, 654, 321, 111)"),
701 "222;333;444;321=111/456=789/987=654";
702is $a, 123;
703
704sub t058 ($a, $b = 333, @c) { "$a;$b;".join("/", @c).";".scalar(@c) }
705is prototype(\&t058), undef;
706is eval("t058()"), undef;
707like $@, qr/\AToo few arguments for subroutine at/;
708is eval("t058(456)"), "456;333;;0";
709is eval("t058(456, 789)"), "456;789;;0";
710is eval("t058(456, 789, 987)"), "456;789;987;1";
711is eval("t058(456, 789, 987, 654)"), "456;789;987/654;2";
712is eval("t058(456, 789, 987, 654, 321)"), "456;789;987/654/321;3";
713is eval("t058(456, 789, 987, 654, 321, 111)"), "456;789;987/654/321/111;4";
714is $a, 123;
715
716eval "#line 8 foo\nsub t059 (\@a, \$b) { }";
717is $@, "Slurpy parameter not last at foo line 8\.\n";
718
719eval "#line 8 foo\nsub t060 (\@a, \$b = 222) { }";
720is $@, "Slurpy parameter not last at foo line 8\.\n";
721
722eval "#line 8 foo\nsub t061 (\@a, \@b) { }";
723is $@, "Slurpy parameter not last at foo line 8\.\n";
724
725eval "#line 8 foo\nsub t062 (\@a, \%b) { }";
726is $@, "Slurpy parameter not last at foo line 8\.\n";
727
728eval "#line 8 foo\nsub t063 (\@, \$b) { }";
729is $@, "Slurpy parameter not last at foo line 8\.\n";
730
731eval "#line 8 foo\nsub t064 (\@, \$b = 222) { }";
732is $@, "Slurpy parameter not last at foo line 8\.\n";
733
734eval "#line 8 foo\nsub t065 (\@, \@b) { }";
735is $@, "Slurpy parameter not last at foo line 8\.\n";
736
737eval "#line 8 foo\nsub t066 (\@, \%b) { }";
738is $@, "Slurpy parameter not last at foo line 8\.\n";
739
740eval "#line 8 foo\nsub t067 (\@a, \$) { }";
741is $@, "Slurpy parameter not last at foo line 8\.\n";
742
743eval "#line 8 foo\nsub t068 (\@a, \$ = 222) { }";
744is $@, "Slurpy parameter not last at foo line 8\.\n";
745
746eval "#line 8 foo\nsub t069 (\@a, \@) { }";
747is $@, "Slurpy parameter not last at foo line 8\.\n";
748
749eval "#line 8 foo\nsub t070 (\@a, \%) { }";
750is $@, "Slurpy parameter not last at foo line 8\.\n";
751
752eval "#line 8 foo\nsub t071 (\@, \$) { }";
753is $@, "Slurpy parameter not last at foo line 8\.\n";
754
755eval "#line 8 foo\nsub t072 (\@, \$ = 222) { }";
756is $@, "Slurpy parameter not last at foo line 8\.\n";
757
758eval "#line 8 foo\nsub t073 (\@, \@) { }";
759is $@, "Slurpy parameter not last at foo line 8\.\n";
760
761eval "#line 8 foo\nsub t074 (\@, \%) { }";
762is $@, "Slurpy parameter not last at foo line 8\.\n";
763
764eval "#line 8 foo\nsub t075 (\%a, \$b) { }";
765is $@, "Slurpy parameter not last at foo line 8\.\n";
766
767eval "#line 8 foo\nsub t076 (\%, \$b) { }";
768is $@, "Slurpy parameter not last at foo line 8\.\n";
769
770eval "#line 8 foo\nsub t077 (\$a, \@b, \$c) { }";
771is $@, "Slurpy parameter not last at foo line 8\.\n";
772
773eval "#line 8 foo\nsub t078 (\$a, \%b, \$c) { }";
774is $@, "Slurpy parameter not last at foo line 8\.\n";
775
776eval "#line 8 foo\nsub t079 (\$a, \@b, \$c, \$d) { }";
777is $@, "Slurpy parameter not last at foo line 8\.\n";
778
779sub t080 ($a,,, $b) { $a.$b }
780is prototype(\&t080), undef;
781is eval("t080()"), undef;
782like $@, qr/\AToo few arguments for subroutine at/;
783is eval("t080(456)"), undef;
784like $@, qr/\AToo few arguments for subroutine at/;
785is eval("t080(456, 789)"), "456789";
786is eval("t080(456, 789, 987)"), undef;
787like $@, qr/\AToo many arguments for subroutine at/;
788is eval("t080(456, 789, 987, 654)"), undef;
789like $@, qr/\AToo many arguments for subroutine at/;
790is $a, 123;
791
792sub t081 ($a, $b,,) { $a.$b }
793is prototype(\&t081), undef;
794is eval("t081()"), undef;
795like $@, qr/\AToo few arguments for subroutine at/;
796is eval("t081(456)"), undef;
797like $@, qr/\AToo few arguments for subroutine at/;
798is eval("t081(456, 789)"), "456789";
799is eval("t081(456, 789, 987)"), undef;
800like $@, qr/\AToo many arguments for subroutine at/;
801is eval("t081(456, 789, 987, 654)"), undef;
802like $@, qr/\AToo many arguments for subroutine at/;
803is $a, 123;
804
805eval "#line 8 foo\nsub t082 (, \$a) { }";
806like $@, qr/\AParse error at foo line 8\.\n/;
807
808eval "#line 8 foo\nsub t083 (,) { }";
809like $@, qr/\AParse error at foo line 8\.\n/;
810
811sub t084($a,$b){ $a.$b }
812is prototype(\&t084), undef;
813is eval("t084()"), undef;
814like $@, qr/\AToo few arguments for subroutine at/;
815is eval("t084(456)"), undef;
816like $@, qr/\AToo few arguments for subroutine at/;
817is eval("t084(456, 789)"), "456789";
818is eval("t084(456, 789, 987)"), undef;
819like $@, qr/\AToo many arguments for subroutine at/;
820is eval("t084(456, 789, 987, 654)"), undef;
821like $@, qr/\AToo many arguments for subroutine at/;
822is $a, 123;
823
824sub t085
825 (
826 $
827 a
828 ,
829 ,
830 $
831 b
832 =
833 333
834 ,
835 ,
836 )
837 { $a.$b }
838is prototype(\&t085), undef;
839is eval("t085()"), undef;
840like $@, qr/\AToo few arguments for subroutine at/;
841is eval("t085(456)"), "456333";
842is eval("t085(456, 789)"), "456789";
843is eval("t085(456, 789, 987)"), undef;
844like $@, qr/\AToo many arguments for subroutine at/;
845is eval("t085(456, 789, 987, 654)"), undef;
846like $@, qr/\AToo many arguments for subroutine at/;
847is $a, 123;
848
849sub t086
850 ( #foo)))
851 $ #foo)))
852 a #foo)))
853 , #foo)))
854 , #foo)))
855 $ #foo)))
856 b #foo)))
857 = #foo)))
858 333 #foo)))
859 , #foo)))
860 , #foo)))
861 ) #foo)))
862 { $a.$b }
863is prototype(\&t086), undef;
864is eval("t086()"), undef;
865like $@, qr/\AToo few arguments for subroutine at/;
866is eval("t086(456)"), "456333";
867is eval("t086(456, 789)"), "456789";
868is eval("t086(456, 789, 987)"), undef;
869like $@, qr/\AToo many arguments for subroutine at/;
870is eval("t086(456, 789, 987, 654)"), undef;
871like $@, qr/\AToo many arguments for subroutine at/;
872is $a, 123;
873
874sub t087
875 (#foo)))
876 $ #foo)))
877 a#foo)))
878 ,#foo)))
879 ,#foo)))
880 $ #foo)))
881 b#foo)))
882 =#foo)))
883 333#foo)))
884 ,#foo)))
885 ,#foo)))
886 )#foo)))
887 { $a.$b }
888is prototype(\&t087), undef;
889is eval("t087()"), undef;
890like $@, qr/\AToo few arguments for subroutine at/;
891is eval("t087(456)"), "456333";
892is eval("t087(456, 789)"), "456789";
893is eval("t087(456, 789, 987)"), undef;
894like $@, qr/\AToo many arguments for subroutine at/;
895is eval("t087(456, 789, 987, 654)"), undef;
896like $@, qr/\AToo many arguments for subroutine at/;
897is $a, 123;
898
899eval "#line 8 foo\nsub t088 (\$ #foo\na) { }";
900is $@, "";
901
902eval "#line 8 foo\nsub t089 (\$#foo\na) { }";
903like $@, qr/\AParse error at foo line 8\.\n/;
904
905eval "#line 8 foo\nsub t090 (\@ #foo\na) { }";
906is $@, "";
907
908eval "#line 8 foo\nsub t091 (\@#foo\na) { }";
909like $@, qr/\AParse error at foo line 8\.\n/;
910
911eval "#line 8 foo\nsub t092 (\% #foo\na) { }";
912is $@, "";
913
914eval "#line 8 foo\nsub t093 (\%#foo\na) { }";
915like $@, qr/\AParse error at foo line 8\.\n/;
916
917eval "#line 8 foo\nsub t094 (123) { }";
918like $@, qr/\AParse error at foo line 8\.\n/;
919
920eval "#line 8 foo\nsub t095 (\$a, 123) { }";
921like $@, qr/\AParse error at foo line 8\.\n/;
922
923eval "#line 8 foo\nsub t096 (\$a 123) { }";
924like $@, qr/\AParse error at foo line 8\.\n/;
925
926eval "#line 8 foo\nsub t097 (\$a { }) { }";
927like $@, qr/\AParse error at foo line 8\.\n/;
928
929eval "#line 8 foo\nsub t098 (\$a; \$b) { }";
930like $@, qr/\AParse error at foo line 8\.\n/;
931
932eval "#line 8 foo\nsub t099 (\$\$) { }";
933like $@, qr/\AParse error at foo line 8\.\n/;
934
935no warnings "experimental::lexical_topic";
936sub t100 ($_) { "$::_/$_" }
937is prototype(\&t100), undef;
938$_ = "___";
939is eval("t100()"), undef;
940like $@, qr/\AToo few arguments for subroutine at/;
941$_ = "___";
942is eval("t100(0)"), "___/0";
943$_ = "___";
944is eval("t100(456)"), "___/456";
945$_ = "___";
946is eval("t100(456, 789)"), undef;
947like $@, qr/\AToo many arguments for subroutine at/;
948$_ = "___";
949is eval("t100(456, 789, 987)"), undef;
950like $@, qr/\AToo many arguments for subroutine at/;
951is $a, 123;
952
953eval "#line 8 foo\nsub t101 (\@_) { }";
954like $@, qr/\ACan't use global \@_ in "my" at foo line 8/;
955
956eval "#line 8 foo\nsub t102 (\%_) { }";
957like $@, qr/\ACan't use global \%_ in "my" at foo line 8/;
958
959my $t103 = sub ($a) { $a || "z" };
960is prototype($t103), undef;
961is eval("\$t103->()"), undef;
962like $@, qr/\AToo few arguments for subroutine at/;
963is eval("\$t103->(0)"), "z";
964is eval("\$t103->(456)"), 456;
965is eval("\$t103->(456, 789)"), undef;
966like $@, qr/\AToo many arguments for subroutine at/;
967is eval("\$t103->(456, 789, 987)"), undef;
968like $@, qr/\AToo many arguments for subroutine at/;
969is $a, 123;
970
971my $t118 = sub :prototype($) ($a) { $a || "z" };
972is prototype($t118), "\$";
973is eval("\$t118->()"), undef;
974like $@, qr/\AToo few arguments for subroutine at/;
975is eval("\$t118->(0)"), "z";
976is eval("\$t118->(456)"), 456;
977is eval("\$t118->(456, 789)"), undef;
978like $@, qr/\AToo many arguments for subroutine at/;
979is eval("\$t118->(456, 789, 987)"), undef;
980like $@, qr/\AToo many arguments for subroutine at/;
981is $a, 123;
982
983sub t033 ($a = sub ($a) { $a."z" }) { $a->("a")."y" }
984is prototype(\&t033), undef;
985is eval("t033()"), "azy";
986is eval("t033(sub { \"x\".\$_[0].\"x\" })"), "xaxy";
987is eval("t033(sub { \"x\".\$_[0].\"x\" }, 789)"), undef;
988like $@, qr/\AToo many arguments for subroutine at/;
989is $a, 123;
990
991sub t104 :method ($a) { $a || "z" }
992is prototype(\&t104), undef;
993is eval("t104()"), undef;
994like $@, qr/\AToo few arguments for subroutine at/;
995is eval("t104(0)"), "z";
996is eval("t104(456)"), 456;
997is eval("t104(456, 789)"), undef;
998like $@, qr/\AToo many arguments for subroutine at/;
999is eval("t104(456, 789, 987)"), undef;
1000like $@, qr/\AToo many arguments for subroutine at/;
1001is $a, 123;
1002
1003sub t105 :prototype($) ($a) { $a || "z" }
1004is prototype(\&t105), "\$";
1005is eval("t105()"), undef;
1006like $@, qr/\ANot enough arguments for main::t105 /;
1007is eval("t105(0)"), "z";
1008is eval("t105(456)"), 456;
1009is eval("t105(456, 789)"), undef;
1010like $@, qr/\AToo many arguments for main::t105 at/;
1011is eval("t105(456, 789, 987)"), undef;
1012like $@, qr/\AToo many arguments for main::t105 at/;
1013is $a, 123;
1014
1015sub t106 :prototype(@) ($a) { $a || "z" }
1016is prototype(\&t106), "\@";
1017is eval("t106()"), undef;
1018like $@, qr/\AToo few arguments for subroutine at/;
1019is eval("t106(0)"), "z";
1020is eval("t106(456)"), 456;
1021is eval("t106(456, 789)"), undef;
1022like $@, qr/\AToo many arguments for subroutine at/;
1023is eval("t106(456, 789, 987)"), undef;
1024like $@, qr/\AToo many arguments for subroutine at/;
1025is $a, 123;
1026
1027eval "#line 8 foo\nsub t107 (\$a) :method { }";
1028isnt $@, "";
1029
1030eval "#line 8 foo\nsub t108 (\$a) :prototype(\$) { }";
1031isnt $@, "";
1032
1033sub t109 { }
1034is prototype(\&t109), undef;
1035is scalar(@{[ t109() ]}), 0;
1036is scalar(t109()), undef;
1037
1038sub t110 () { }
1039is prototype(\&t110), undef;
1040is scalar(@{[ t110() ]}), 0;
1041is scalar(t110()), undef;
1042
1043sub t111 ($a) { }
1044is prototype(\&t111), undef;
1045is scalar(@{[ t111(222) ]}), 0;
1046is scalar(t111(222)), undef;
1047
1048sub t112 ($) { }
1049is prototype(\&t112), undef;
1050is scalar(@{[ t112(222) ]}), 0;
1051is scalar(t112(222)), undef;
1052
1053sub t114 ($a = undef) { }
1054is prototype(\&t114), undef;
1055is scalar(@{[ t114() ]}), 0;
1056is scalar(t114()), undef;
1057is scalar(@{[ t114(333) ]}), 0;
1058is scalar(t114(333)), undef;
1059
1060sub t113 ($a = 222) { }
1061is prototype(\&t113), undef;
1062is scalar(@{[ t113() ]}), 0;
1063is scalar(t113()), undef;
1064is scalar(@{[ t113(333) ]}), 0;
1065is scalar(t113(333)), undef;
1066
1067sub t115 ($a = do { $z++; 222 }) { }
1068is prototype(\&t115), undef;
1069$z = 0;
1070is scalar(@{[ t115() ]}), 0;
1071is $z, 1;
1072is scalar(t115()), undef;
1073is $z, 2;
1074is scalar(@{[ t115(333) ]}), 0;
1075is scalar(t115(333)), undef;
1076is $z, 2;
1077
1078sub t116 (@a) { }
1079is prototype(\&t116), undef;
1080is scalar(@{[ t116() ]}), 0;
1081is scalar(t116()), undef;
1082is scalar(@{[ t116(333) ]}), 0;
1083is scalar(t116(333)), undef;
1084
1085sub t117 (%a) { }
1086is prototype(\&t117), undef;
1087is scalar(@{[ t117() ]}), 0;
1088is scalar(t117()), undef;
1089is scalar(@{[ t117(333, 444) ]}), 0;
1090is scalar(t117(333, 444)), undef;
1091
10921;