This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
change#3612 is buggy when quotemeta argument matches target
[perl5.git] / t / pragma / warn / toke
CommitLineData
599cee73
PM
1toke.c AOK
2
3 we seem to have lost a few ambiguous warnings!!
4
5
6 1 if $a EQ $b ;
7 1 if $a NE $b ;
8 1 if $a LT $b ;
9 1 if $a GT $b ;
10 1 if $a GE $b ;
11 1 if $a LE $b ;
12 $a = <<;
13 Use of comma-less variable list is deprecated
14 (called 3 times via depcom)
15
16 \1 better written as $1
4438c4b7 17 use warnings 'syntax' ;
599cee73
PM
18 s/(abc)/\1/;
19
20 warn(warn_nosemi)
21 Semicolon seems to be missing
22 $a = 1
23 &time ;
24
25
26 Reversed %c= operator
27 my $a =+ 2 ;
28 $a =- 2 ;
29 $a =* 2 ;
30 $a =% 2 ;
31 $a =& 2 ;
32 $a =. 2 ;
33 $a =^ 2 ;
34 $a =| 2 ;
35 $a =< 2 ;
36 $a =/ 2 ;
37
38 Multidimensional syntax %.*s not supported
39 my $a = $a[1,2] ;
40
41 You need to quote \"%s\""
42 sub fred {} ; $SIG{TERM} = fred;
43
44 Scalar value %.*s better written as $%.*s"
45 @a[3] = 2;
46 @a{3} = 2;
47
48 Can't use \\%c to mean $%c in expression
49 $_ = "ab" ; s/(ab)/\1/e;
50
51 Unquoted string "abc" may clash with future reserved word at - line 3.
52 warn(warn_reserved
53 $a = abc;
54
55 chmod: mode argument is missing initial 0
56 chmod 3;
57
58 Possible attempt to separate words with commas
59 @a = qw(a, b, c) ;
60
61 Possible attempt to put comments in qw() list
62 @a = qw(a b # c) ;
63
64 umask: argument is missing initial 0
65 umask 3;
66
67 %s (...) interpreted as function
68 print ("")
69 printf ("")
70 sort ("")
71
72 Ambiguous use of %c{%s%s} resolved to %c%s%s
73 $a = ${time[2]}
74 $a = ${time{2}}
75
76
77 Ambiguous use of %c{%s} resolved to %c%s
78 $a = ${time}
79 sub fred {} $a = ${fred}
80
81 Misplaced _ in number
82 $a = 1_2;
83 $a = 1_2345_6;
84
85 Bareword \"%s\" refers to nonexistent package
86 $a = FRED:: ;
87
88 Ambiguous call resolved as CORE::%s(), qualify as such or use &
89 sub time {}
90 my $a = time()
91
92 Use of \\x{} without utf8 declaration
93 $_ = " \x{123} " ;
94
95
96 \x%.*s will produce malformed UTF-8 character; use \x{%.*s} for that
97 use utf8 ;
98 $_ = "\xffe"
99
0453d815
PM
100 Mandatory Warnings
101 ------------------
102 Use of "%s" without parentheses is ambiguous [check_uni]
103 rand + 4
104
105 Ambiguous use of -%s resolved as -&%s() [yylex]
106 sub fred {} ; - fred ;
107
108 Precedence problem: open %.*s should be open(%.*s) [yylex]
109 open FOO || die;
110
111 Operator or semicolon missing before %c%s [yylex]
112 Ambiguous use of %c resolved as operator %c
113 *foo *foo
114
599cee73
PM
115__END__
116# toke.c
4438c4b7 117use warnings 'deprecated' ;
599cee73
PM
1181 if $a EQ $b ;
1191 if $a NE $b ;
1201 if $a GT $b ;
1211 if $a LT $b ;
1221 if $a GE $b ;
1231 if $a LE $b ;
4438c4b7 124no warnings 'deprecated' ;
0453d815
PM
1251 if $a EQ $b ;
1261 if $a NE $b ;
1271 if $a GT $b ;
1281 if $a LT $b ;
1291 if $a GE $b ;
1301 if $a LE $b ;
599cee73
PM
131EXPECT
132Use of EQ is deprecated at - line 3.
133Use of NE is deprecated at - line 4.
134Use of GT is deprecated at - line 5.
135Use of LT is deprecated at - line 6.
136Use of GE is deprecated at - line 7.
137Use of LE is deprecated at - line 8.
138########
139# toke.c
4438c4b7 140use warnings 'deprecated' ;
599cee73
PM
141format STDOUT =
142@<<< @||| @>>> @>>>
143$a $b "abc" 'def'
144.
4438c4b7 145no warnings 'deprecated' ;
0453d815
PM
146format STDOUT =
147@<<< @||| @>>> @>>>
148$a $b "abc" 'def'
149.
599cee73
PM
150EXPECT
151Use of comma-less variable list is deprecated at - line 5.
152Use of comma-less variable list is deprecated at - line 5.
153Use of comma-less variable list is deprecated at - line 5.
599cee73
PM
154########
155# toke.c
4438c4b7 156use warnings 'deprecated' ;
599cee73
PM
157$a = <<;
158
4438c4b7 159no warnings 'deprecated' ;
0453d815
PM
160$a = <<;
161
599cee73
PM
162EXPECT
163Use of bare << to mean <<"" is deprecated at - line 3.
164########
165# toke.c
4438c4b7 166use warnings 'syntax' ;
599cee73 167s/(abc)/\1/;
4438c4b7 168no warnings 'syntax' ;
0453d815 169s/(abc)/\1/;
599cee73
PM
170EXPECT
171\1 better written as $1 at - line 3.
172########
173# toke.c
4438c4b7 174use warnings 'semicolon' ;
599cee73
PM
175$a = 1
176&time ;
4438c4b7 177no warnings 'semicolon' ;
0453d815
PM
178$a = 1
179&time ;
599cee73
PM
180EXPECT
181Semicolon seems to be missing at - line 3.
182########
183# toke.c
e4050d25
GS
184BEGIN {
185 # Scalars leaked: due to syntax errors
186 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
187}
4438c4b7 188use warnings 'syntax' ;
599cee73
PM
189my $a =+ 2 ;
190$a =- 2 ;
191$a =* 2 ;
192$a =% 2 ;
193$a =& 2 ;
194$a =. 2 ;
195$a =^ 2 ;
196$a =| 2 ;
197$a =< 2 ;
198$a =/ 2 ;
199EXPECT
e4050d25
GS
200Reversed += operator at - line 7.
201Reversed -= operator at - line 8.
202Reversed *= operator at - line 9.
203Reversed %= operator at - line 10.
204Reversed &= operator at - line 11.
205Reversed .= operator at - line 12.
206syntax error at - line 12, near "=."
207Reversed ^= operator at - line 13.
208syntax error at - line 13, near "=^"
209Reversed |= operator at - line 14.
210syntax error at - line 14, near "=|"
211Reversed <= operator at - line 15.
212Unterminated <> operator at - line 15.
599cee73
PM
213########
214# toke.c
0453d815
PM
215BEGIN {
216 # Scalars leaked: due to syntax errors
217 $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
218}
4438c4b7 219no warnings 'syntax' ;
0453d815
PM
220my $a =+ 2 ;
221$a =- 2 ;
222$a =* 2 ;
223$a =% 2 ;
224$a =& 2 ;
225$a =. 2 ;
226$a =^ 2 ;
227$a =| 2 ;
228$a =< 2 ;
229$a =/ 2 ;
230EXPECT
231syntax error at - line 12, near "=."
232syntax error at - line 13, near "=^"
233syntax error at - line 14, near "=|"
234Unterminated <> operator at - line 15.
235########
236# toke.c
4438c4b7 237use warnings 'syntax' ;
599cee73 238my $a = $a[1,2] ;
4438c4b7 239no warnings 'syntax' ;
0453d815 240my $a = $a[1,2] ;
599cee73
PM
241EXPECT
242Multidimensional syntax $a[1,2] not supported at - line 3.
243########
244# toke.c
4438c4b7 245use warnings 'syntax' ;
599cee73 246sub fred {} ; $SIG{TERM} = fred;
4438c4b7 247no warnings 'syntax' ;
0453d815 248$SIG{TERM} = fred;
599cee73
PM
249EXPECT
250You need to quote "fred" at - line 3.
251########
252# toke.c
4438c4b7 253use warnings 'syntax' ;
599cee73
PM
254@a[3] = 2;
255@a{3} = 2;
4438c4b7 256no warnings 'syntax' ;
0453d815
PM
257@a[3] = 2;
258@a{3} = 2;
599cee73
PM
259EXPECT
260Scalar value @a[3] better written as $a[3] at - line 3.
261Scalar value @a{3} better written as $a{3} at - line 4.
262########
263# toke.c
4438c4b7 264use warnings 'syntax' ;
599cee73
PM
265$_ = "ab" ;
266s/(ab)/\1/e;
4438c4b7 267no warnings 'syntax' ;
0453d815
PM
268$_ = "ab" ;
269s/(ab)/\1/e;
599cee73
PM
270EXPECT
271Can't use \1 to mean $1 in expression at - line 4.
272########
273# toke.c
4438c4b7 274use warnings 'reserved' ;
599cee73 275$a = abc;
4438c4b7 276no warnings 'reserved' ;
0453d815 277$a = abc;
599cee73
PM
278EXPECT
279Unquoted string "abc" may clash with future reserved word at - line 3.
280########
281# toke.c
4438c4b7 282use warnings 'octal' ;
599cee73 283chmod 3;
4438c4b7 284no warnings 'octal' ;
0453d815 285chmod 3;
599cee73 286EXPECT
4438c4b7 287chmod: mode argument is missing initial 0 at - line 3.
599cee73
PM
288########
289# toke.c
4438c4b7 290use warnings 'syntax' ;
599cee73 291@a = qw(a, b, c) ;
4438c4b7 292no warnings 'syntax' ;
0453d815 293@a = qw(a, b, c) ;
599cee73
PM
294EXPECT
295Possible attempt to separate words with commas at - line 3.
296########
297# toke.c
4438c4b7 298use warnings 'syntax' ;
599cee73 299@a = qw(a b #) ;
4438c4b7 300no warnings 'syntax' ;
0453d815 301@a = qw(a b #) ;
599cee73
PM
302EXPECT
303Possible attempt to put comments in qw() list at - line 3.
304########
305# toke.c
4438c4b7 306use warnings 'octal' ;
599cee73 307umask 3;
4438c4b7 308no warnings 'octal' ;
0453d815 309umask 3;
599cee73 310EXPECT
4438c4b7 311umask: argument is missing initial 0 at - line 3.
599cee73
PM
312########
313# toke.c
4438c4b7 314use warnings 'syntax' ;
599cee73
PM
315print ("")
316EXPECT
317print (...) interpreted as function at - line 3.
318########
319# toke.c
4438c4b7 320no warnings 'syntax' ;
0453d815
PM
321print ("")
322EXPECT
323
324########
325# toke.c
4438c4b7 326use warnings 'syntax' ;
599cee73
PM
327printf ("")
328EXPECT
329printf (...) interpreted as function at - line 3.
330########
331# toke.c
4438c4b7 332no warnings 'syntax' ;
0453d815
PM
333printf ("")
334EXPECT
335
336########
337# toke.c
4438c4b7 338use warnings 'syntax' ;
599cee73
PM
339sort ("")
340EXPECT
341sort (...) interpreted as function at - line 3.
342########
343# toke.c
4438c4b7 344no warnings 'syntax' ;
0453d815
PM
345sort ("")
346EXPECT
347
348########
349# toke.c
4438c4b7 350use warnings 'ambiguous' ;
599cee73 351$a = ${time[2]};
4438c4b7 352no warnings 'ambiguous' ;
0453d815 353$a = ${time[2]};
599cee73
PM
354EXPECT
355Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
356########
357# toke.c
4438c4b7 358use warnings 'ambiguous' ;
599cee73
PM
359$a = ${time{2}};
360EXPECT
361Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
362########
363# toke.c
4438c4b7 364no warnings 'ambiguous' ;
0453d815
PM
365$a = ${time{2}};
366EXPECT
367
368########
369# toke.c
4438c4b7 370use warnings 'ambiguous' ;
599cee73 371$a = ${time} ;
4438c4b7 372no warnings 'ambiguous' ;
0453d815 373$a = ${time} ;
599cee73
PM
374EXPECT
375Ambiguous use of ${time} resolved to $time at - line 3.
376########
377# toke.c
4438c4b7 378use warnings 'ambiguous' ;
599cee73
PM
379sub fred {}
380$a = ${fred} ;
4438c4b7 381no warnings 'ambiguous' ;
0453d815 382$a = ${fred} ;
599cee73
PM
383EXPECT
384Ambiguous use of ${fred} resolved to $fred at - line 4.
385########
386# toke.c
4438c4b7 387use warnings 'syntax' ;
599cee73
PM
388$a = 1_2;
389$a = 1_2345_6;
4438c4b7 390no warnings 'syntax' ;
0453d815
PM
391$a = 1_2;
392$a = 1_2345_6;
599cee73
PM
393EXPECT
394Misplaced _ in number at - line 3.
395Misplaced _ in number at - line 4.
396Misplaced _ in number at - line 4.
397########
398# toke.c
4438c4b7 399use warnings 'unsafe' ;
60e6418e 400#line 25 "bar"
599cee73 401$a = FRED:: ;
4438c4b7 402no warnings 'unsafe' ;
0453d815
PM
403#line 25 "bar"
404$a = FRED:: ;
599cee73 405EXPECT
60e6418e 406Bareword "FRED::" refers to nonexistent package at bar line 25.
599cee73
PM
407########
408# toke.c
4438c4b7 409use warnings 'ambiguous' ;
599cee73 410sub time {}
0453d815 411my $a = time() ;
4438c4b7 412no warnings 'ambiguous' ;
0453d815 413my $b = time() ;
599cee73
PM
414EXPECT
415Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
416########
417# toke.c
4438c4b7 418use warnings 'utf8' ;
60e6418e
GS
419eval <<'EOE';
420{
421#line 30 "foo"
422 $_ = " \x{123} " ;
423}
424EOE
599cee73 425EXPECT
60e6418e 426Use of \x{} without utf8 declaration at foo line 30.
599cee73
PM
427########
428# toke.c
4438c4b7 429no warnings 'utf8' ;
0453d815
PM
430eval <<'EOE';
431{
432#line 30 "foo"
433 $_ = " \x{123} " ;
434}
435EOE
436EXPECT
437
438########
439# toke.c
4438c4b7 440use warnings 'utf8' ;
599cee73
PM
441use utf8 ;
442$_ = " \xffe " ;
4438c4b7 443no warnings 'utf8' ;
0453d815 444$_ = " \xffe " ;
599cee73
PM
445EXPECT
446\xff will produce malformed UTF-8 character; use \x{ff} for that at - line 4.
0453d815
PM
447########
448# toke.c
449my $a = rand + 4 ;
450EXPECT
451Warning: Use of "rand" without parens is ambiguous at - line 2.
452########
453# toke.c
454$^W = 0 ;
455my $a = rand + 4 ;
456{
4438c4b7 457 no warnings 'ambiguous' ;
0453d815 458 $a = rand + 4 ;
4438c4b7 459 use warnings 'ambiguous' ;
0453d815
PM
460 $a = rand + 4 ;
461}
462$a = rand + 4 ;
463EXPECT
464Warning: Use of "rand" without parens is ambiguous at - line 3.
465Warning: Use of "rand" without parens is ambiguous at - line 8.
466Warning: Use of "rand" without parens is ambiguous at - line 10.
467########
468# toke.c
469sub fred {};
470-fred ;
471EXPECT
472Ambiguous use of -fred resolved as -&fred() at - line 3.
473########
474# toke.c
475$^W = 0 ;
476sub fred {} ;
477-fred ;
478{
4438c4b7 479 no warnings 'ambiguous' ;
0453d815 480 -fred ;
4438c4b7 481 use warnings 'ambiguous' ;
0453d815
PM
482 -fred ;
483}
484-fred ;
485EXPECT
486Ambiguous use of -fred resolved as -&fred() at - line 4.
487Ambiguous use of -fred resolved as -&fred() at - line 9.
488Ambiguous use of -fred resolved as -&fred() at - line 11.
489########
490# toke.c
491open FOO || time;
492EXPECT
493Precedence problem: open FOO should be open(FOO) at - line 2.
494########
495# toke.c
496$^W = 0 ;
497open FOO || time;
498{
4438c4b7 499 no warnings 'ambiguous' ;
0453d815 500 open FOO || time;
4438c4b7 501 use warnings 'ambiguous' ;
0453d815
PM
502 open FOO || time;
503}
504open FOO || time;
505EXPECT
506Precedence problem: open FOO should be open(FOO) at - line 3.
507Precedence problem: open FOO should be open(FOO) at - line 8.
508Precedence problem: open FOO should be open(FOO) at - line 10.
509########
510# toke.c
511$^W = 0 ;
512*foo *foo ;
513{
4438c4b7 514 no warnings 'ambiguous' ;
0453d815 515 *foo *foo ;
4438c4b7 516 use warnings 'ambiguous' ;
0453d815
PM
517 *foo *foo ;
518}
519*foo *foo ;
520EXPECT
521Operator or semicolon missing before *foo at - line 3.
522Ambiguous use of * resolved as operator * at - line 3.
523Operator or semicolon missing before *foo at - line 8.
524Ambiguous use of * resolved as operator * at - line 8.
525Operator or semicolon missing before *foo at - line 10.
526Ambiguous use of * resolved as operator * at - line 10.