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