Merge pull request #189 from sinkuu/fix_analyzer_crash

Fix dub.json and analyzer crashes
This commit is contained in:
Brian Schott 2014-07-09 18:29:03 +00:00
commit 3abeced177
3 changed files with 45 additions and 24 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);

View File

@ -74,18 +74,23 @@ class BackwardsRangeCheck : BaseAnalyzer
override void visit(const PrimaryExpression primary)
{
import std.conv;
if (state == State.ignore || !isNumberLiteral(primary.primary.type))
return;
if (state == State.left)
{
line = primary.primary.line;
this.column = primary.primary.column;
left = parseNumber(primary.primary.text);
try left = parseNumber(primary.primary.text);
catch (ConvException e) return;
hasLeft = true;
}
else
{
right = parseNumber(primary.primary.text);
try right = parseNumber(primary.primary.text);
catch (ConvException e) return;
hasRight = true;
}
}

View File

@ -1,20 +1,10 @@
{
"name": "dscanner",
"description": "Swiss-army knife for D source code",
"copyright": "© Brian Schott",
"authors": ["Brian Schott"],
"importPaths": ["."],
"name": "dscanner",
"description": "Swiss-army knife for D source code",
"copyright": "© Brian Schott",
"authors": ["Brian Schott"],
"license" : "Boost Software License - Version 1.0",
"configurations": [
{
"name": "library",
"targetType": "library",
"sourcePaths": ["std"],
},
{
"name": "dscanner",
"targetType": "executable",
"sourcePaths": ["."],
},
],
"targetType": "executable",
"sourcePaths": ["."],
"excludedSourceFiles": ["inifiled/inifiled.d", "inifiled/test.d"],
}