xref: /openbsd-src/gnu/usr.bin/perl/t/lib/croak/op (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1898184e3Ssthen__END__
2b8851fccSafresh1# NAME join,
3b8851fccSafresh1join,
4b8851fccSafresh1EXPECT
5b8851fccSafresh1Not enough arguments for join or string at - line 1, near "join,"
6b8851fccSafresh1Execution of - aborted due to compilation errors.
7b8851fccSafresh1########
8898184e3Ssthen# NAME my $<special>
9898184e3Ssthenmy $!;
10898184e3SsthenEXPECT
11898184e3SsthenCan't use global $! in "my" at - line 1, near "my $!"
12898184e3SsthenExecution of - aborted due to compilation errors.
13898184e3Ssthen########
14b8851fccSafresh1# NAME my $<non-ASCII> doesn't output garbage
15b8851fccSafresh1# \xB6 is same character in all three EBCDIC pages and Latin1
16b8851fccSafresh1use open ":std", ":utf8";
17b8851fccSafresh1eval qq|my \$\xb6;|; # ¶ in Latin-1, and EBCDIC 1047, 037, POSIX-BC
18b8851fccSafresh1print $@;
19b8851fccSafresh1exit 1;
20b8851fccSafresh1EXPECT
21b8851fccSafresh1Can't use global $¶ in "my" at (eval 1) line 1, near "my $¶"
22b8851fccSafresh1########
23898184e3Ssthen# NAME OP_HELEM fields
24898184e3Ssthenpackage Foo;
25898184e3Ssthenuse fields qw(a b);
26898184e3Ssthensub new {
27898184e3Ssthen    my $class = shift;
28898184e3Ssthen    return fields::new($class);
29898184e3Ssthen}
30898184e3Ssthenmy Foo $f = Foo->new;
31898184e3Ssthen$f->{c} = 1;
32898184e3SsthenEXPECT
33898184e3SsthenNo such class field "c" in variable $f of type Foo at - line 8.
34898184e3Ssthen########
356fb12b70Safresh1# NAME "No such field" with block: ${$ref}{key}
366fb12b70Safresh1%FIELDS; # empty hash so all keys are invalid
376fb12b70Safresh1my main $r;
386fb12b70Safresh1${$r}{key};
396fb12b70Safresh1EXPECT
406fb12b70Safresh1No such class field "key" in variable $r of type main at - line 3.
416fb12b70Safresh1########
42898184e3Ssthen# NAME OP_HSLICE fields
43898184e3Ssthenpackage Foo;
44898184e3Ssthenuse fields qw(a b);
45898184e3Ssthensub new {
46898184e3Ssthen    my $class = shift;
47898184e3Ssthen    return fields::new($class);
48898184e3Ssthen}
49898184e3Ssthenmy Foo $f = Foo->new;
50898184e3Ssthen@$f{"a", "c"} = ( 1, 2 );
51898184e3SsthenEXPECT
52898184e3SsthenNo such class field "c" in variable $f of type Foo at - line 8.
53898184e3Ssthen########
546fb12b70Safresh1# NAME Single OP_HSLICE field
556fb12b70Safresh1%FIELDS; # vivify it, but leave it empty, so all fields are invalid
566fb12b70Safresh1my main $f;
576fb12b70Safresh1@$f{"a"};
586fb12b70Safresh1EXPECT
596fb12b70Safresh1No such class field "a" in variable $f of type main at - line 3.
606fb12b70Safresh1########
616fb12b70Safresh1# NAME OP_KVHSLICE fields
626fb12b70Safresh1BEGIN { %FIELDS = qw(a 1 b 1); }
636fb12b70Safresh1my main $f;
646fb12b70Safresh1%$f{"a","c"};
656fb12b70Safresh1EXPECT
666fb12b70Safresh1No such class field "c" in variable $f of type main at - line 3.
676fb12b70Safresh1########
68c0dd97bfSafresh1# NAME Num-specific &= on @array
69c0dd97bfSafresh1use feature 'bitwise';
70c0dd97bfSafresh1@a &= 1;
71c0dd97bfSafresh1EXPECT
72c0dd97bfSafresh1Can't modify array dereference in numeric bitwise and (&) at - line 2, near "1;"
73c0dd97bfSafresh1Execution of - aborted due to compilation errors.
74c0dd97bfSafresh1########
75c0dd97bfSafresh1# NAME Num-specific |= on @array
76c0dd97bfSafresh1use feature 'bitwise';
77c0dd97bfSafresh1@a |= 1;
78c0dd97bfSafresh1EXPECT
79c0dd97bfSafresh1Can't modify array dereference in numeric bitwise or (|) at - line 2, near "1;"
80c0dd97bfSafresh1Execution of - aborted due to compilation errors.
81c0dd97bfSafresh1########
82c0dd97bfSafresh1# NAME Num-specific ^= on @array
83c0dd97bfSafresh1use feature 'bitwise';
84c0dd97bfSafresh1@a ^= 1;
85c0dd97bfSafresh1EXPECT
86c0dd97bfSafresh1Can't modify array dereference in numeric bitwise xor (^) at - line 2, near "1;"
87c0dd97bfSafresh1Execution of - aborted due to compilation errors.
88c0dd97bfSafresh1########
89c0dd97bfSafresh1# NAME &.= on @array
90c0dd97bfSafresh1use feature 'bitwise';
91c0dd97bfSafresh1@a &.= 1;
92c0dd97bfSafresh1EXPECT
93c0dd97bfSafresh1Can't modify array dereference in string bitwise and (&.) at - line 2, near "1;"
94c0dd97bfSafresh1Execution of - aborted due to compilation errors.
95c0dd97bfSafresh1########
96c0dd97bfSafresh1# NAME |.= on @array
97c0dd97bfSafresh1use feature 'bitwise';
98c0dd97bfSafresh1@a |.= 1;
99c0dd97bfSafresh1EXPECT
100c0dd97bfSafresh1Can't modify array dereference in string bitwise or (|.) at - line 2, near "1;"
101c0dd97bfSafresh1Execution of - aborted due to compilation errors.
102c0dd97bfSafresh1########
103c0dd97bfSafresh1# NAME ^.= on @array
104c0dd97bfSafresh1use feature 'bitwise';
105c0dd97bfSafresh1@a ^.= 1;
106c0dd97bfSafresh1EXPECT
107c0dd97bfSafresh1Can't modify array dereference in string bitwise xor (^.) at - line 2, near "1;"
108c0dd97bfSafresh1Execution of - aborted due to compilation errors.
109c0dd97bfSafresh1########
1109f11ffb7Safresh1# NAME substr %h in scalar assignment
1119f11ffb7Safresh1substr(%h,0) = 3;
1129f11ffb7Safresh1EXPECT
1139f11ffb7Safresh1Can't modify hash dereference in substr at - line 1, near "3;"
1149f11ffb7Safresh1Execution of - aborted due to compilation errors.
1159f11ffb7Safresh1########
1169f11ffb7Safresh1# NAME substr %h in list assignment
1179f11ffb7Safresh1(substr %h,0) = 3;
1189f11ffb7Safresh1EXPECT
1199f11ffb7Safresh1Can't modify hash dereference in substr at - line 1, near "3;"
1209f11ffb7Safresh1Execution of - aborted due to compilation errors.
1219f11ffb7Safresh1########
1229f11ffb7Safresh1# NAME vec %h in scalar assignment
1239f11ffb7Safresh1vec(%h,1,1) = 3;
1249f11ffb7Safresh1EXPECT
1259f11ffb7Safresh1Can't modify hash dereference in vec at - line 1, near "3;"
1269f11ffb7Safresh1Execution of - aborted due to compilation errors.
1279f11ffb7Safresh1########
1289f11ffb7Safresh1# NAME vec %h in list assignment
1299f11ffb7Safresh1(vec %h,1,1) = 3;
1309f11ffb7Safresh1EXPECT
1319f11ffb7Safresh1Can't modify hash dereference in vec at - line 1, near "3;"
1329f11ffb7Safresh1Execution of - aborted due to compilation errors.
1339f11ffb7Safresh1########
1346fb12b70Safresh1# NAME Can't declare conditional
1356fb12b70Safresh1my($a?$b:$c)
1366fb12b70Safresh1EXPECT
1376fb12b70Safresh1Can't declare conditional expression in "my" at - line 1, at EOF
1386fb12b70Safresh1Execution of - aborted due to compilation errors.
1396fb12b70Safresh1########
1406fb12b70Safresh1# NAME Can't declare do block
1416fb12b70Safresh1my(do{})
1426fb12b70Safresh1EXPECT
1436fb12b70Safresh1Can't declare do block in "my" at - line 1, at EOF
1446fb12b70Safresh1Execution of - aborted due to compilation errors.
1456fb12b70Safresh1########
146b8851fccSafresh1# NAME ($_, state $x) = ...
147b8851fccSafresh1($_, CORE::state $x) = ();
148b8851fccSafresh1EXPECT
1499f11ffb7Safresh1Initialization of state variables in list currently forbidden at - line 1, near ");"
150b8851fccSafresh1Execution of - aborted due to compilation errors.
151b8851fccSafresh1########
152b8851fccSafresh1# NAME my $y; ($y, state $x) = ...
153b8851fccSafresh1my $y; ($y, CORE::state $x) = ();
154b8851fccSafresh1EXPECT
1559f11ffb7Safresh1Initialization of state variables in list currently forbidden at - line 1, near ");"
156b8851fccSafresh1Execution of - aborted due to compilation errors.
157b8851fccSafresh1########
158898184e3Ssthen# NAME delete BAD
159898184e3Ssthendelete $x;
160898184e3SsthenEXPECT
161898184e3Ssthendelete argument is not a HASH or ARRAY element or slice at - line 1.
162898184e3Ssthen########
1636fb12b70Safresh1# NAME delete sort
1646fb12b70Safresh1use warnings;
165eac174f2Safresh1delete sort 1; # used to warn about scalar context, too
1666fb12b70Safresh1EXPECT
1676fb12b70Safresh1delete argument is not a HASH or ARRAY element or slice at - line 2.
1686fb12b70Safresh1########
169898184e3Ssthen# NAME exists BAD
170898184e3Ssthenexists $x;
171898184e3SsthenEXPECT
172898184e3Ssthenexists argument is not a HASH or ARRAY element or a subroutine at - line 1.
173898184e3Ssthen########
174898184e3Ssthen# NAME exists non-sub
175898184e3Ssthenexists &foo()
176898184e3SsthenEXPECT
177898184e3Ssthenexists argument is not a subroutine name at - line 1.
178b8851fccSafresh1########
179b8851fccSafresh1# NAME push BAREWORD
180b8851fccSafresh1push FRED;
181b8851fccSafresh1EXPECT
182b8851fccSafresh1Type of arg 1 to push must be array (not constant item) at - line 1, near "FRED;"
183b8851fccSafresh1Execution of - aborted due to compilation errors.
184b8851fccSafresh1########
185b8851fccSafresh1# NAME pop BAREWORD
186b8851fccSafresh1pop FRED;
187b8851fccSafresh1EXPECT
188b8851fccSafresh1Type of arg 1 to pop must be array (not constant item) at - line 1, near "FRED;"
189b8851fccSafresh1Execution of - aborted due to compilation errors.
190b8851fccSafresh1########
191b8851fccSafresh1# NAME shift BAREWORD
192b8851fccSafresh1shift FRED;
193b8851fccSafresh1EXPECT
194b8851fccSafresh1Type of arg 1 to shift must be array (not constant item) at - line 1, near "FRED;"
195b8851fccSafresh1Execution of - aborted due to compilation errors.
196b8851fccSafresh1########
197b8851fccSafresh1# NAME unshift BAREWORD
198b8851fccSafresh1unshift FRED;
199b8851fccSafresh1EXPECT
200b8851fccSafresh1Type of arg 1 to unshift must be array (not constant item) at - line 1, near "FRED;"
201b8851fccSafresh1Execution of - aborted due to compilation errors.
202b8851fccSafresh1########
203b8851fccSafresh1# NAME keys BAREWORD
204b8851fccSafresh1@a = keys FRED ;
205b8851fccSafresh1EXPECT
2069f11ffb7Safresh1Type of arg 1 to keys must be hash or array (not constant item) at - line 1, near "FRED ;"
207b8851fccSafresh1Execution of - aborted due to compilation errors.
208b8851fccSafresh1########
209b8851fccSafresh1# NAME values BAREWORD
210b8851fccSafresh1@a = values FRED ;
211b8851fccSafresh1EXPECT
2129f11ffb7Safresh1Type of arg 1 to values must be hash or array (not constant item) at - line 1, near "FRED ;"
213b8851fccSafresh1Execution of - aborted due to compilation errors.
214b8851fccSafresh1########
215b8851fccSafresh1# NAME each BAREWORD
216b8851fccSafresh1@a = each FRED ;
217b8851fccSafresh1EXPECT
2189f11ffb7Safresh1Type of arg 1 to each must be hash or array (not constant item) at - line 1, near "FRED ;"
219b8851fccSafresh1Execution of - aborted due to compilation errors.
220b46d8ef2Safresh1########
221b46d8ef2Safresh1# NAME better messages for array-ops on non-arrays
222b46d8ef2Safresh1push %a, 1;
223b46d8ef2Safresh1pop %a;
224b46d8ef2Safresh1shift %a;
225b46d8ef2Safresh1unshift %a, 1;
226b46d8ef2Safresh1push *a, 1;
227b46d8ef2Safresh1pop *a;
228b46d8ef2Safresh1shift *a;
229b46d8ef2Safresh1unshift *a, 1;
230b46d8ef2Safresh1EXPECT
231b46d8ef2Safresh1Type of arg 1 to push must be array (not hash dereference) at - line 1, near "1;"
232b46d8ef2Safresh1Type of arg 1 to pop must be array (not hash dereference) at - line 2, near "%a;"
233b46d8ef2Safresh1Type of arg 1 to shift must be array (not hash dereference) at - line 3, near "%a;"
234b46d8ef2Safresh1Type of arg 1 to unshift must be array (not hash dereference) at - line 4, near "1;"
235b46d8ef2Safresh1Type of arg 1 to push must be array (not ref-to-glob cast) at - line 5, near "1;"
236b46d8ef2Safresh1Type of arg 1 to pop must be array (not ref-to-glob cast) at - line 6, near "*a;"
237b46d8ef2Safresh1Type of arg 1 to shift must be array (not ref-to-glob cast) at - line 7, near "*a;"
238b46d8ef2Safresh1Type of arg 1 to unshift must be array (not ref-to-glob cast) at - line 8, near "1;"
239b46d8ef2Safresh1Execution of - aborted due to compilation errors.
240b46d8ef2Safresh1########
241b46d8ef2Safresh1# NAME better messages for array-ops on non-arrays (part 2)
242b46d8ef2Safresh1# to check PADHV without hitting the reported error limit
243b46d8ef2Safresh1my %a;
244b46d8ef2Safresh1push %a, 1;
245b46d8ef2Safresh1pop %a;
246b46d8ef2Safresh1shift %a;
247b46d8ef2Safresh1unshift %a, 1;
248b46d8ef2Safresh1EXPECT
249b46d8ef2Safresh1Type of arg 1 to push must be array (not private hash) at - line 3, near "1;"
250b46d8ef2Safresh1Type of arg 1 to pop must be array (not private hash) at - line 4, near "%a;"
251b46d8ef2Safresh1Type of arg 1 to shift must be array (not private hash) at - line 5, near "%a;"
252b46d8ef2Safresh1Type of arg 1 to unshift must be array (not private hash) at - line 6, near "1;"
253b46d8ef2Safresh1Execution of - aborted due to compilation errors.
254e0680481Safresh1########
255e0680481Safresh1use feature 'defer';
256e0680481Safresh1no warnings 'experimental::defer';
257e0680481Safresh1defer { return "retval" }
258e0680481Safresh1EXPECT
259e0680481Safresh1Can't "return" out of a "defer" block at - line 3.
260e0680481Safresh1########
261e0680481Safresh1use feature 'defer';
262e0680481Safresh1no warnings 'experimental::defer';
263e0680481Safresh1defer { goto HERE }
264e0680481Safresh1HERE:
265e0680481Safresh1EXPECT
266e0680481Safresh1Can't "goto" out of a "defer" block at - line 3.
267e0680481Safresh1########
268e0680481Safresh1use feature 'defer';
269e0680481Safresh1no warnings 'experimental::defer';
270e0680481Safresh1my $subB = sub {};
271e0680481Safresh1defer { goto &$subB }
272e0680481Safresh1EXPECT
273e0680481Safresh1Can't "goto" out of a "defer" block at - line 4.
274e0680481Safresh1########
275e0680481Safresh1use feature 'defer';
276e0680481Safresh1no warnings 'experimental::defer';
277e0680481Safresh1LOOP: while(1) {
278e0680481Safresh1  defer { last LOOP }
279e0680481Safresh1}
280e0680481Safresh1EXPECT
281e0680481Safresh1Can't "last" out of a "defer" block at - line 4.
282e0680481Safresh1########
283e0680481Safresh1use feature 'try';
284e0680481Safresh1no warnings 'experimental::try';
285e0680481Safresh1try {} catch ($e) {} finally { return "123" }
286e0680481Safresh1EXPECT
287e0680481Safresh1Can't "return" out of a "finally" block at - line 3.
288e0680481Safresh1########
289e0680481Safresh1use feature 'try';
290e0680481Safresh1no warnings 'experimental::try';
291e0680481Safresh1try {} catch ($e) {} finally { goto HERE; }
292e0680481Safresh1HERE:
293e0680481Safresh1EXPECT
294e0680481Safresh1Can't "goto" out of a "finally" block at - line 3.
295e0680481Safresh1########
296e0680481Safresh1use feature 'try';
297e0680481Safresh1no warnings 'experimental::try';
298e0680481Safresh1LOOP: {
299e0680481Safresh1  try {} catch ($e) {} finally { last LOOP; }
300e0680481Safresh1}
301e0680481Safresh1EXPECT
302e0680481Safresh1Can't "last" out of a "finally" block at - line 4.
303*3d61058aSafresh1########
304*3d61058aSafresh1# NAME return HANDLE LIST isn't valid [github #21716]
305*3d61058aSafresh1sub xx {
306*3d61058aSafresh1  return sum map { $_+1} 1 .. 5;
307*3d61058aSafresh1}
308*3d61058aSafresh1EXPECT
309*3d61058aSafresh1Missing comma after first argument to return at - line 2, near "5;"
310*3d61058aSafresh1Execution of - aborted due to compilation errors.
311*3d61058aSafresh1########
312*3d61058aSafresh1# subsequent use VERSION to 5.39
313*3d61058aSafresh1use v5.20;
314*3d61058aSafresh1use v5.39;
315*3d61058aSafresh1EXPECT
316*3d61058aSafresh1use VERSION of 5.39 or above is not permitted while another use VERSION is in scope at - line 3.
317*3d61058aSafresh1########
318*3d61058aSafresh1# subsequent use VERSION from 5.39
319*3d61058aSafresh1use v5.39;
320*3d61058aSafresh1use v5.20;
321*3d61058aSafresh1EXPECT
322*3d61058aSafresh1use VERSION is not permitted while another use VERSION of 5.39 or above is in scope at - line 3.
323*3d61058aSafresh1########
324*3d61058aSafresh1# use VERSION across the 5.11 boundary
325*3d61058aSafresh1use 5.012;
326*3d61058aSafresh1use 5.010;
327*3d61058aSafresh1EXPECT
328*3d61058aSafresh1Downgrading a use VERSION declaration to below v5.11 is not permitted at - line 3.
329