Patch to JPL example program
[p5sagit/p5-mst-13.2.git] / t / pragma / warn / toke
1 toke.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 
17         use warning 'syntax' ;
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      
100 __END__
101 # toke.c 
102 use warning 'deprecated' ;
103 1 if $a EQ $b ;
104 1 if $a NE $b ;
105 1 if $a GT $b ;
106 1 if $a LT $b ;
107 1 if $a GE $b ;
108 1 if $a LE $b ;
109 EXPECT
110 Use of EQ is deprecated at - line 3.
111 Use of NE is deprecated at - line 4.
112 Use of GT is deprecated at - line 5.
113 Use of LT is deprecated at - line 6.
114 Use of GE is deprecated at - line 7.
115 Use of LE is deprecated at - line 8.
116 ########
117 # toke.c
118 use warning 'deprecated' ;
119 format STDOUT =
120 @<<<  @|||  @>>>  @>>>
121 $a    $b    "abc" 'def'
122 .
123 ($a, $b) = (1,2,3);
124 write;
125 EXPECT
126 Use of comma-less variable list is deprecated at - line 5.
127 Use of comma-less variable list is deprecated at - line 5.
128 Use of comma-less variable list is deprecated at - line 5.
129 1      2     abc   def
130 ########
131 # toke.c
132 use warning 'deprecated' ;
133 $a = <<;
134
135 EXPECT
136 Use of bare << to mean <<"" is deprecated at - line 3.
137 ########
138 # toke.c
139 use warning 'syntax' ;
140 s/(abc)/\1/;
141 EXPECT
142 \1 better written as $1 at - line 3.
143 ########
144 # toke.c
145 use warning 'semicolon' ;
146 $a = 1
147 &time ;
148 EXPECT
149 Semicolon seems to be missing at - line 3.
150 ########
151 # toke.c
152 BEGIN {
153     # Scalars leaked: due to syntax errors
154     $ENV{PERL_DESTRUCT_LEVEL} = 0 unless $ENV{PERL_DESTRUCT_LEVEL} > 3;
155 }
156 use warning 'syntax' ;
157 my $a =+ 2 ;
158 $a =- 2 ;
159 $a =* 2 ;
160 $a =% 2 ;
161 $a =& 2 ;
162 $a =. 2 ;
163 $a =^ 2 ;
164 $a =| 2 ;
165 $a =< 2 ;
166 $a =/ 2 ;
167 EXPECT
168 Reversed += operator at - line 7.
169 Reversed -= operator at - line 8.
170 Reversed *= operator at - line 9.
171 Reversed %= operator at - line 10.
172 Reversed &= operator at - line 11.
173 Reversed .= operator at - line 12.
174 syntax error at - line 12, near "=."
175 Reversed ^= operator at - line 13.
176 syntax error at - line 13, near "=^"
177 Reversed |= operator at - line 14.
178 syntax error at - line 14, near "=|"
179 Reversed <= operator at - line 15.
180 Unterminated <> operator at - line 15.
181 ########
182 # toke.c
183 use warning 'syntax' ;
184 my $a = $a[1,2] ;
185 EXPECT
186 Multidimensional syntax $a[1,2] not supported at - line 3.
187 ########
188 # toke.c
189 use warning 'syntax' ;
190 sub fred {} ; $SIG{TERM} = fred;
191 EXPECT
192 You need to quote "fred" at - line 3.
193 ########
194 # toke.c
195 use warning 'syntax' ;
196 @a[3] = 2;
197 @a{3} = 2;
198 EXPECT
199 Scalar value @a[3] better written as $a[3] at - line 3.
200 Scalar value @a{3} better written as $a{3} at - line 4.
201 ########
202 # toke.c
203 use warning 'syntax' ;
204 $_ = "ab" ; 
205 s/(ab)/\1/e;
206 EXPECT
207 Can't use \1 to mean $1 in expression at - line 4.
208 ########
209 # toke.c
210 use warning 'reserved' ;
211 $a = abc;
212 EXPECT
213 Unquoted string "abc" may clash with future reserved word at - line 3.
214 ########
215 # toke.c
216 use warning 'octal' ;
217 chmod 3;
218 EXPECT
219 chmod: mode argument is missing initial 0 at - line 3, at end of line
220 ########
221 # toke.c
222 use warning 'syntax' ;
223 @a = qw(a, b, c) ;
224 EXPECT
225 Possible attempt to separate words with commas at - line 3.
226 ########
227 # toke.c
228 use warning 'syntax' ;
229 @a = qw(a b #) ;
230 EXPECT
231 Possible attempt to put comments in qw() list at - line 3.
232 ########
233 # toke.c
234 use warning 'octal' ;
235 umask 3;
236 EXPECT
237 umask: argument is missing initial 0 at - line 3, at end of line
238 ########
239 # toke.c
240 use warning 'syntax' ;
241 print ("")
242 EXPECT
243 print (...) interpreted as function at - line 3.
244 ########
245 # toke.c
246 use warning 'syntax' ;
247 printf ("")
248 EXPECT
249 printf (...) interpreted as function at - line 3.
250 ########
251 # toke.c
252 use warning 'syntax' ;
253 sort ("")
254 EXPECT
255 sort (...) interpreted as function at - line 3.
256 ########
257 # toke.c
258 use warning 'ambiguous' ;
259 $a = ${time[2]};
260 EXPECT
261 Ambiguous use of ${time[...]} resolved to $time[...] at - line 3.
262 ########
263 # toke.c
264 use warning 'ambiguous' ;
265 $a = ${time{2}};
266 EXPECT
267 Ambiguous use of ${time{...}} resolved to $time{...} at - line 3.
268 ########
269 # toke.c
270 use warning 'ambiguous' ;
271 $a = ${time} ;
272 EXPECT
273 Ambiguous use of ${time} resolved to $time at - line 3.
274 ########
275 # toke.c
276 use warning 'ambiguous' ;
277 sub fred {}
278 $a = ${fred} ;
279 EXPECT
280 Ambiguous use of ${fred} resolved to $fred at - line 4.
281 ########
282 # toke.c
283 use warning 'syntax' ;
284 $a = 1_2;
285 $a = 1_2345_6;
286 EXPECT
287 Misplaced _ in number at - line 3.
288 Misplaced _ in number at - line 4.
289 Misplaced _ in number at - line 4.
290 ########
291 # toke.c
292 use warning 'unsafe' ;
293 #line 25 "bar"
294 $a = FRED:: ;
295 EXPECT
296 Bareword "FRED::" refers to nonexistent package at bar line 25.
297 ########
298 # toke.c
299 use warning 'ambiguous' ;
300 sub time {}
301 my $a = time() 
302 EXPECT
303 Ambiguous call resolved as CORE::time(), qualify as such or use & at - line 4.
304 ########
305 # toke.c
306 use warning 'utf8' ;
307 eval <<'EOE';
308 {
309 #line 30 "foo"
310   $_ = " \x{123} " ;
311 }
312 EOE
313 EXPECT
314 Use of \x{} without utf8 declaration at foo line 30.
315 ########
316 # toke.c
317 use warning 'utf8' ;
318 use utf8 ;
319 $_ = " \xffe " ;
320 EXPECT
321 \xff will produce malformed UTF-8 character; use \x{ff} for that at - line 4.