Skip to content

Commit

Permalink
Fix #334
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackerpilot committed Apr 18, 2016
1 parent d62a572 commit 9b81989
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions src/analysis/label_var_same_name_check.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module analysis.label_var_same_name_check;

import dparse.ast;
import dparse.lexer;

import dsymbol.scope_ : Scope;
import analysis.base;
import analysis.helpers;

Expand All @@ -20,33 +20,13 @@ class LabelVarNameCheck : BaseAnalyzer
super(fileName, sc);
}

override void visit(const Module mod)
{
pushScope();
mod.accept(this);
popScope();
}

override void visit(const BlockStatement block)
{
pushScope();
block.accept(this);
popScope();
}

override void visit(const StructBody structBody)
{
pushScope();
structBody.accept(this);
popScope();
}

override void visit(const CaseStatement caseStatement)
{
pushScope();
caseStatement.accept(this);
popScope();
}
mixin ScopedVisit!Module;
mixin ScopedVisit!BlockStatement;
mixin ScopedVisit!StructBody;
mixin ScopedVisit!CaseStatement;
mixin ScopedVisit!ForStatement;
mixin ScopedVisit!IfStatement;
mixin ScopedVisit!TemplateDeclaration;

override void visit(const VariableDeclaration var)
{
Expand Down Expand Up @@ -76,6 +56,16 @@ private:

Thing[string][] stack;

template ScopedVisit(NodeType)
{
override void visit(const NodeType n)
{
pushScope();
n.accept(this);
popScope();
}
}

void duplicateCheck(const Token name, bool fromLabel, bool isConditional)
{
import std.conv : to;
Expand Down Expand Up @@ -163,6 +153,21 @@ unittest
int a = 20;
int a; // [warn]: Variable "a" has the same name as a variable defined on line 28.
}
template T(stuff)
{
int b;
}

void main(string[] args)
{
for (int a = 0; a < 10; a++)
things(a);

for (int a = 0; a < 10; a++)
things(a);
int b;
}

}c, sac);
stderr.writeln("Unittest for LabelVarNameCheck passed.");
}

0 comments on commit 9b81989

Please sign in to comment.