This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t give unavailability warnings about our vars
[perl5.git] / t / lib / warnings / pad
CommitLineData
f21d7107
DM
1 pad.c AOK
2
7f73a9f1 3 "%s" variable %s masks earlier declaration in same scope
f21d7107
DM
4 my $x;
5 my $x ;
6
b5c19bd7 7 Variable "%s" will not stay shared
f21d7107
DM
8 sub x {
9 my $x;
10 sub y {
b5c19bd7 11 sub { $x }
f21d7107
DM
12 }
13 }
14
f21d7107
DM
15 sub x {
16 my $x;
17 sub y {
b5c19bd7 18 $x
f21d7107
DM
19 }
20 }
b5c19bd7 21
f21d7107
DM
22 "our" variable %s redeclared (Did you mean "local" instead of "our"?)
23 our $x;
24 {
25 our $x;
26 }
27
28 %s never introduced [pad_leavemy] TODO
29
30__END__
31# pad.c
32use warnings 'misc' ;
33my $x ;
34my $x ;
35my $y = my $y ;
f2f96cd5
RGS
36my $p ;
37package X ;
38my $p ;
39package main ;
f21d7107
DM
40no warnings 'misc' ;
41my $x ;
42my $y ;
f2f96cd5 43my $p ;
f21d7107
DM
44EXPECT
45"my" variable $x masks earlier declaration in same scope at - line 4.
46"my" variable $y masks earlier declaration in same statement at - line 5.
f2f96cd5 47"my" variable $p masks earlier declaration in same scope at - line 8.
f21d7107
DM
48########
49# pad.c
f793795c
RGS
50use warnings 'misc' ;
51our $x ;
f793795c
RGS
52my $x ;
53our $y = my $y ;
f2f96cd5
RGS
54our $p ;
55package X ;
56my $p ;
57package main ;
f793795c
RGS
58no warnings 'misc' ;
59our $z ;
60my $z ;
61our $t = my $t ;
f2f96cd5
RGS
62our $q ;
63package X ;
64my $q ;
f793795c
RGS
65EXPECT
66"my" variable $x masks earlier declaration in same scope at - line 4.
67"my" variable $y masks earlier declaration in same statement at - line 5.
f2f96cd5 68"my" variable $p masks earlier declaration in same scope at - line 8.
f793795c
RGS
69########
70# pad.c
f793795c
RGS
71use warnings 'misc' ;
72my $x ;
73our $x ;
74my $y = our $y ;
f2f96cd5
RGS
75my $p ;
76package X ;
77our $p ;
78package main ;
f793795c
RGS
79no warnings 'misc' ;
80my $z ;
81our $z ;
82my $t = our $t ;
f2f96cd5
RGS
83my $q ;
84package X ;
85our $q ;
f793795c 86EXPECT
f2f96cd5
RGS
87"our" variable $x masks earlier declaration in same scope at - line 4.
88"our" variable $y masks earlier declaration in same statement at - line 5.
89"our" variable $p masks earlier declaration in same scope at - line 8.
f793795c
RGS
90########
91# pad.c
f21d7107
DM
92use warnings 'closure' ;
93sub x {
94 my $x;
95 sub y {
96 $x
97 }
98 }
99EXPECT
100Variable "$x" will not stay shared at - line 7.
101########
102# pad.c
103no warnings 'closure' ;
104sub x {
105 my $x;
106 sub y {
107 $x
108 }
109 }
110EXPECT
111
112########
113# pad.c
114use warnings 'closure' ;
115sub x {
b5c19bd7 116 my $x;
f21d7107 117 sub y {
b5c19bd7 118 sub { $x }
f21d7107
DM
119 }
120 }
121EXPECT
b5c19bd7
DM
122Variable "$x" will not stay shared at - line 6.
123########
124# pad.c
125use warnings 'closure' ;
126sub x {
127 my $x;
128 sub {
129 $x;
130 sub y {
131 $x
132 }
133 }->();
134}
135EXPECT
136Variable "$x" will not stay shared at - line 9.
137########
138# pad.c
139use warnings 'closure' ;
140my $x;
141sub {
142 $x;
143 sub f {
144 sub { $x }->();
145 }
146}->();
147EXPECT
f21d7107
DM
148
149########
150# pad.c
151use warnings 'closure' ;
b5c19bd7
DM
152sub {
153 my $x;
154 sub f { $x }
155}->();
156EXPECT
157Variable "$x" is not available at - line 5.
158########
159# pad.c
160use warnings 'closure' ;
161sub {
162 my $x;
163 eval 'sub f { $x }';
164}->();
165EXPECT
166
167########
168# pad.c
169use warnings 'closure' ;
170sub {
171 my $x;
172 sub f { eval '$x' }
173}->();
174f();
175EXPECT
451f421f 176Variable "$x" is not available at (eval 1) line 1.
b5c19bd7
DM
177########
178# pad.c
179use warnings 'closure' ;
f21d7107 180sub x {
b5c19bd7 181 our $x;
f21d7107 182 sub y {
b5c19bd7 183 $x
f21d7107
DM
184 }
185 }
186EXPECT
b5c19bd7
DM
187
188########
189# pad.c
190# see bugid 1754
191use warnings 'closure' ;
192sub f {
193 my $x;
194 sub { eval '$x' };
195}
196f()->();
197EXPECT
451f421f 198Variable "$x" is not available at (eval 1) line 1.
f21d7107 199########
2740392c
DM
200use warnings 'closure' ;
201{
202 my $x = 1;
203 $y = \$x; # force abandonment rather than clear-in-place at scope exit
204 sub f2 { eval '$x' }
205}
206f2();
207EXPECT
451f421f 208Variable "$x" is not available at (eval 1) line 1.
2740392c 209########
14f338dc
DM
210use warnings 'closure' ;
211for my $x (1,2,3) {
212 sub f { eval '$x' }
213 f();
214}
215f();
216EXPECT
451f421f 217Variable "$x" is not available at (eval 4) line 1.
14f338dc 218########
f21d7107
DM
219# pad.c
220no warnings 'closure' ;
221sub x {
222 my $x;
223 sub y {
224 sub { $x }
225 }
226 }
227EXPECT
228
229########
f2047bf1
FC
230# pad.c
231use warnings 'closure';
232my $x;
233our $y;
234sub { $x = $y }->(); # should not warn about $y being unavailable
235EXPECT
236########
f21d7107 237use warnings 'misc' ;
f2f96cd5
RGS
238my $x;
239{
240 my $x;
241}
242EXPECT
243########
7f73a9f1
RGS
244# pad.c
245use warnings 'misc' ;
246our $x ;
247our $x ;
248our $y = our $y ;
249our $p ;
250package X ;
251our $p ;
252package main ;
253no warnings 'misc' ;
254our $a ;
255our $a ;
256our $b = our $b ;
257our $c ;
258package X ;
259our $c ;
260EXPECT
261"our" variable $x redeclared at - line 4.
262"our" variable $y redeclared at - line 5.
263########
f2f96cd5 264use warnings 'misc' ;
f21d7107
DM
265our $x;
266{
267 our $x;
268}
7f73a9f1
RGS
269our $x;
270no warnings 'misc' ;
271our $y;
272{
273 our $y;
274}
275our $y;
f21d7107
DM
276EXPECT
277"our" variable $x redeclared at - line 4.
278 (Did you mean "local" instead of "our"?)
7f73a9f1 279"our" variable $x redeclared at - line 6.
929a0744 280########
f2f96cd5
RGS
281use warnings 'misc' ;
282our $x;
283{
284 my $x;
285}
7f73a9f1
RGS
286no warnings 'misc' ;
287our $y;
288{
289 my $y;
290}
f2f96cd5
RGS
291EXPECT
292########
293use warnings 'misc' ;
294my $x;
295{
296 our $x;
297}
7f73a9f1
RGS
298no warnings 'misc' ;
299my $y;
300{
301 our $y;
302}
303EXPECT
304########
305use warnings 'misc' ;
306my $x;
307{
308 my $x;
309}
310no warnings 'misc' ;
311my $y;
312{
313 my $y;
314}
f2f96cd5
RGS
315EXPECT
316########
929a0744
DM
317# an our var being introduced should suppress errors about global syms
318use strict;
319use warnings;
320our $x unless $x;
321EXPECT
1456f925
NC
322########
323use warnings 'misc';
324our $qunckkk;
325our $_;
326package clank_est;
327our $qunckkk;
328our $_;
329no warnings 'misc';
330our $ouch;
331our $_;
332package whack;
333our $ouch;
334our $_;
335EXPECT
336"our" variable $_ redeclared at - line 6.
0727928e
BF
337########
338use warnings 'misc';
339BEGIN { binmode STDERR, 'utf8'; }
340{
341 use utf8;
342 my $ニコニコ;
343 my $ニコニコ;
344}
345EXPECT
346"my" variable $ニコニコ masks earlier declaration in same scope at - line 6.
347########
348use warnings 'misc';
349BEGIN { binmode STDERR, 'utf8'; }
350{
351 use utf8;
352 my $thìs;
353 my $thìs;
354}
355EXPECT
356"my" variable $thìs masks earlier declaration in same scope at - line 6.
357########
358# pad.c
359use warnings 'closure' ;
360BEGIN { binmode STDERR, 'utf8'; }
361sub {
362 use utf8;
363 my $è;
364 sub f { $è }
365}->();
366EXPECT
367Variable "$è" is not available at - line 7.
368########
369# pad.c
370use warnings 'closure' ;
371BEGIN { binmode STDERR, 'utf8'; }
372sub {
373 use utf8;
374 my $ニ;
375 sub f { $ニ }
376}->();
377EXPECT
378Variable "$ニ" is not available at - line 7.
379########
380# pad.c
381use warnings 'closure' ;
382BEGIN { binmode STDERR, 'utf8'; }
383sub x {
384 use utf8;
385 my $に;
386 sub y {
387 $に
388 }
389 }
390EXPECT
391Variable "$に" will not stay shared at - line 9.
392########
393# pad.c
394use warnings 'closure' ;
395BEGIN { binmode STDERR, 'utf8'; }
396sub x {
397 use utf8;
398 my $に;
399 sub y {
400 sub { $に }
401 }
402 }
403EXPECT
404Variable "$に" will not stay shared at - line 8.
405########
406# pad.c
407use warnings 'closure' ;
408BEGIN { binmode STDERR, 'utf8'; }
409sub x {
410 use utf8;
411 my $に;
412 sub {
413 $に;
414 sub y {
415 $に
416 }
417 }->();
418}
419EXPECT
420Variable "$に" will not stay shared at - line 11.
421########
422# pad.c
423use warnings 'closure' ;
424BEGIN { binmode STDERR, 'utf8'; }
425sub {
426 use utf8;
427 my $に;
428 sub f { $に }
429}->();
430EXPECT
431Variable "$に" is not available at - line 7.
432########
433# pad.c
434use warnings 'closure' ;
435BEGIN { binmode STDERR, 'utf8'; }
436sub {
437 use utf8;
438 my $に;
439 sub f { eval '$に' }
440}->();
441f();
442EXPECT
451f421f 443Variable "$に" is not available at (eval 1) line 1.
0727928e
BF
444########
445# pad.c
446# see bugid 1754
447use warnings 'closure' ;
448BEGIN { binmode STDERR, 'utf8'; }
449sub f {
450 use utf8;
451 my $に;
452 sub { eval '$に' };
453}
454f()->();
455EXPECT
451f421f 456Variable "$に" is not available at (eval 1) line 1.
0727928e
BF
457########
458use warnings 'closure' ;
459BEGIN { binmode STDERR, 'utf8'; }
460{
461 use utf8;
462 my $に = 1;
463 $y = \$に; # force abandonment rather than clear-in-place at scope exit
464 sub f2 { eval '$に' }
465}
466f2();
467EXPECT
451f421f 468Variable "$に" is not available at (eval 1) line 1.
0727928e
BF
469########
470use warnings 'closure' ;
471BEGIN { binmode STDERR, 'utf8'; }
472use utf8;
473for my $に (1,2,3) {
474 sub f { eval '$に' }
475 f();
476}
477f();
478EXPECT
451f421f 479Variable "$に" is not available at (eval 4) line 1.
0727928e
BF
480########
481# pad.c
482use warnings 'closure' ;
483BEGIN { binmode STDERR, 'utf8'; }
484sub x {
485 use utf8;
486 my $è;
487 sub y {
488
489 }
490 }
491EXPECT
492Variable "$è" will not stay shared at - line 9.
493########
494# pad.c
495use warnings 'closure' ;
496BEGIN { binmode STDERR, 'utf8'; }
497sub x {
498 use utf8;
499 my $è;
500 sub y {
501 sub { $è }
502 }
503 }
504EXPECT
505Variable "$è" will not stay shared at - line 8.
506########
507# pad.c
508use warnings 'closure' ;
509BEGIN { binmode STDERR, 'utf8'; }
510sub x {
511 use utf8;
512 my $è;
513 sub {
514 $è;
515 sub y {
516
517 }
518 }->();
519}
520EXPECT
521Variable "$è" will not stay shared at - line 11.
522########
523# pad.c
524use warnings 'closure' ;
525BEGIN { binmode STDERR, 'utf8'; }
526sub {
527 use utf8;
528 my $è;
529 sub f { $è }
530}->();
531EXPECT
532Variable "$è" is not available at - line 7.
533########
534# pad.c
535use warnings 'closure' ;
536BEGIN { binmode STDERR, 'utf8'; }
537sub {
538 use utf8;
539 my $è;
540 sub f { eval '$è' }
541}->();
542f();
543EXPECT
451f421f 544Variable "$è" is not available at (eval 1) line 1.
0727928e
BF
545########
546# pad.c
547# see bugid 1754
548use warnings 'closure' ;
549BEGIN { binmode STDERR, 'utf8'; }
550sub f {
551 use utf8;
552 my $è;
553 sub { eval '$è' };
554}
555f()->();
556EXPECT
451f421f 557Variable "$è" is not available at (eval 1) line 1.
0727928e
BF
558########
559use warnings 'closure' ;
560BEGIN { binmode STDERR, 'utf8'; }
561{
562 use utf8;
563 my $è = 1;
564 $y = \$è; # force abandonment rather than clear-in-place at scope exit
565 sub f2 { eval '$è' }
566}
567f2();
568EXPECT
451f421f 569Variable "$è" is not available at (eval 1) line 1.
0727928e
BF
570########
571use warnings 'closure' ;
572BEGIN { binmode STDERR, 'utf8'; }
573use utf8;
574for my $è (1,2,3) {
575 sub f { eval '$è' }
576 f();
577}
578f();
579EXPECT
451f421f 580Variable "$è" is not available at (eval 4) line 1.
0727928e 581########