@@ -6,7 +6,7 @@ module analysis.label_var_same_name_check;
6
6
7
7
import dparse.ast;
8
8
import dparse.lexer;
9
-
9
+ import dsymbol.scope_ : Scope;
10
10
import analysis.base;
11
11
import analysis.helpers;
12
12
@@ -20,33 +20,13 @@ class LabelVarNameCheck : BaseAnalyzer
20
20
super (fileName, sc);
21
21
}
22
22
23
- override void visit (const Module mod)
24
- {
25
- pushScope();
26
- mod.accept(this );
27
- popScope();
28
- }
29
-
30
- override void visit (const BlockStatement block)
31
- {
32
- pushScope();
33
- block.accept(this );
34
- popScope();
35
- }
36
-
37
- override void visit (const StructBody structBody)
38
- {
39
- pushScope();
40
- structBody.accept(this );
41
- popScope();
42
- }
43
-
44
- override void visit (const CaseStatement caseStatement)
45
- {
46
- pushScope();
47
- caseStatement.accept(this );
48
- popScope();
49
- }
23
+ mixin ScopedVisit! Module;
24
+ mixin ScopedVisit! BlockStatement;
25
+ mixin ScopedVisit! StructBody;
26
+ mixin ScopedVisit! CaseStatement;
27
+ mixin ScopedVisit! ForStatement;
28
+ mixin ScopedVisit! IfStatement;
29
+ mixin ScopedVisit! TemplateDeclaration;
50
30
51
31
override void visit (const VariableDeclaration var)
52
32
{
@@ -76,6 +56,16 @@ private:
76
56
77
57
Thing[string ][] stack;
78
58
59
+ template ScopedVisit (NodeType)
60
+ {
61
+ override void visit (const NodeType n)
62
+ {
63
+ pushScope();
64
+ n.accept(this );
65
+ popScope();
66
+ }
67
+ }
68
+
79
69
void duplicateCheck (const Token name, bool fromLabel, bool isConditional)
80
70
{
81
71
import std.conv : to;
@@ -163,6 +153,21 @@ unittest
163
153
int a = 20 ;
164
154
int a; // [warn]: Variable "a" has the same name as a variable defined on line 28.
165
155
}
156
+ template T (stuff)
157
+ {
158
+ int b;
159
+ }
160
+
161
+ void main (string [] args)
162
+ {
163
+ for (int a = 0 ; a < 10 ; a++ )
164
+ things(a);
165
+
166
+ for (int a = 0 ; a < 10 ; a++ )
167
+ things(a);
168
+ int b;
169
+ }
170
+
166
171
}c, sac);
167
172
stderr.writeln(" Unittest for LabelVarNameCheck passed." );
168
173
}
0 commit comments