summaryrefslogtreecommitdiff
path: root/README.lexwarn
blob: 27e5ec810cdae88a4e1ed4db065b971d296ed185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Date: 29th July 1998

This patch adds lexical warnings to Perl. It should apply over
5.005_50

NOTE: This is a prototype. Do not assume that lexical warnings will
      necessarily be anything like this implementation.

Changes 
=======

  Date: 8th April 1998

    * patch now applies cleanly over 5.004_64

    * added the -X switch (the inverse "lint" command)

  Date: 26th Feb 1997

    * By popular demand, the warnings bitmask can now be of arbitrary
      length. The code uses an SV* to store the bitmask.

    * Rationalised the warning categories a bit. This area still needs
      a lot of work.

    * Added -W switch (the "lint" command).

    * Added an experimental feature to allow warnings to be excalated
      to fatal errors.


The "use warning" pragma
========================

    The "use warning" pragma is intended to replace both the use of the
    command line flag "-w" and its equivalent variable $^W with a pragma
    that works like the existing "strict" pragma.

    This means that the scope of the pragma is limited to the enclosing
    block. It also means that that a pragma setting will not leak across
    files (via use/require/do). This will allow authors to define the
    degree of warning checks that will be applied to their module.

    By default warnings are disabled.

    All warnings are enabled in a block by either of these:

	use warning ;
	use warning 'all' ;

    Similarly all warnings are disabled in a block by either of these:

	no warning ;
	no warning 'all' ;

    A hierarchy of "categories" have been defined to allow groups of
    warnings to be enabled/disabled in isolation.  The current
    hierarchy is:

	all - +--- unsafe -------+--- taint
	      |			 |
	      |			 +--- substr
	      |			 |
	      |			 +--- signal
	      |			 |
	      |			 +--- closure
	      |			 |
	      |			 +--- untie
	      |			 
	      +--- io	---------+--- pipe
	      |			 |
	      |			 +--- unopened
	      |			 |
	      |			 +--- closed
	      |			 |
	      |			 +--- newline
	      |			 |
	      |			 +--- exec
	      |
	      +--- syntax    ----+--- ambiguous
	      |			 |
	      |			 +--- semicolon
	      |			 |
	      |			 +--- precedence
	      |			 |
	      |			 +--- reserved
	      |			 |
	      |			 +--- octal
	      |			 |
	      |			 +--- parenthesis
	      |			 |
	      |			 +--- deprecated
	      |
	      |--- uninitialized
	      |
	      +--- void
	      |
	      +--- recursion
	      |
	      +--- redefine
	      |
	      +--- numeric
	      |
	      +--- once
	      |
	      +--- misc

    This hierarchy is very tentative. Feedback is needed.

    Just like the "strict" pragma any of these categories can be
    combined

	use warning qw(void redefine) ;
	no warning qw(io syntax untie) ;

The "lint" flag, -W
===================

If the -W flag is used on the command line, it will enable all warnings
throughout the program regardless of whether warnings were disabled
locally using "no warning" or $^W =0. This includes any file that gets
included during compilation via use/require.

The inverse "lint" flag, -X
===========================
Does exactly the same as the -W flag, except it disables all warnings.


Backward Compatability
======================

    How Lexical Warnings interact with -w/$^W

    1. The -w flag just sets the global $^W variable as in 5.004
       This means that any legacy code that currently relies on
       manipulating $^W to control warning behaviour will still work.

    2. Apart from now being a boolean, the $^W variable operates in
       exactly the same horrible uncontrolled global way as in 5.004,
       except...

    3. If a piece of code is under the control of a lexical warning
       pragma, the $^W variable will be ignored.
 
       The combined effect of 2 & 3 is that it will will allow new code
       which will use the lexical warning pragma to control old
       $^W-type code (using a local $^W=0) if it really wants to, but
       not vice-versa.
 
    4. The only way to override a lexical warnings setting is with the
       new -W or -X command line flags.


Fatal Warnings
==============

This feature is very experimental.

The presence of the word "FATAL" in the category list will escalate any
warnings from the category specified that are detected in the lexical
scope into fatal errors. In the code below, there are 3 places where a
deprecated warning will be detected, the middle one will produce a
fatal error.


    use warning ;

    $a = 1 if $a EQ $b ;

    {
	use warning qw(FATAL deprecated) ;
        $a = 1 if $a EQ $b ;
    }

    $a = 1 if $a EQ $b ;


TODO
====

test harness for -X (assuming it is a permanent fixture).
win32, os2 & vms all have warnings. These need to be included.

Unresolved Issues
=================

  The pragma name?
    A few possibilities:
	warning
	warnings
	warn

  Hierarchy of Warnings
    The current patch has a fairly arbitrary hierarchy.
    Ideas for a useful hierarchy would be most welcome.

  A command line option to turn off all warnings?
     -X or -q, perhaps.

  Current mandatory warnings.
    May be useful to bring them under the control of this pragma.

  Severity
    Do we want/need a severity classification?
        pedantic
        high/strict/precise
        medium/default
        low/common
    
  Versions
    This is a thorhy issue. Say someone writes a script using Perl
    5.004 and places this at the top:

	use warning ;

    Time passes and 5.005 comes out. It has added a few extra warnings.
    The script prints warning messages.

    A possibility is to allow the warnings that are checked to be
    limited to those available in a given version of Perl. A possible
    syntax could be:

	use warning 5.004 ;

    or

	use warning 5.004 qw(void uninitialized) ;

    Do we really need this amount of control?

  Documentation
    There isn't any yet.


  perl5db.pl
    The debugger saves and restores $^W at runtime. I haven't checked
    whether the debugger will still work with the lexical warnings
    patch applied.

  diagnostics.pm
    I *think* I've got diagnostics to work with the lexiacal warnings
    patch, but there were design decisions made in diagnostics to work
    around the limitations of $^W. Now that those limitations are gone,
    the module should be revisited.