Fix PokemonExceptionCheck causes segfault on nested attributes

This commit is contained in:
sinkuu 2014-07-09 18:10:50 +09:00
parent 114f8880fb
commit 0acd33f48b
1 changed files with 31 additions and 5 deletions

View File

@ -40,17 +40,35 @@ class PokemonExceptionCheck : BaseAnalyzer
lc.accept(this);
}
bool ignoreType = true;
override void visit(const Catch c)
{
if (c.type.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length != 1)
ignoreType = false;
c.type.accept(this);
ignoreType = true;
c.accept(this);
}
override void visit(const Type2 type2)
{
if (ignoreType) return;
if (type2.type !is null)
{
c.accept(this);
type2.type.accept(this);
return;
}
auto identOrTemplate = c.type.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances[0];
if (type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length != 1)
{
return;
}
auto identOrTemplate = type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances[0];
if (identOrTemplate.templateInstance !is null)
{
c.accept(this);
return;
}
if (identOrTemplate.identifier.text == "Throwable"
@ -60,7 +78,6 @@ class PokemonExceptionCheck : BaseAnalyzer
immutable line = identOrTemplate.identifier.line;
addErrorMessage(line, column, message);
}
c.accept(this);
}
}
@ -83,6 +100,10 @@ unittest
catch (Exception err) // ok
{
}
catch (shared(Exception) err) // ok
{
}
catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea.
{
@ -91,9 +112,14 @@ unittest
catch (Throwable err) // [warn]: Catching Error or Throwable is almost always a bad idea.
{
}
catch (shared(Error) err) // [warn]: Catching Error or Throwable is almost always a bad idea.
{
}
catch // [warn]: Catching Error or Throwable is almost always a bad idea.
{
}
}
}c, sac);