Merge pull request 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); lc.accept(this);
} }
bool ignoreType = true;
override void visit(const Catch c) 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; 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) if (identOrTemplate.templateInstance !is null)
{ {
c.accept(this);
return; return;
} }
if (identOrTemplate.identifier.text == "Throwable" if (identOrTemplate.identifier.text == "Throwable"
@ -60,7 +78,6 @@ class PokemonExceptionCheck : BaseAnalyzer
immutable line = identOrTemplate.identifier.line; immutable line = identOrTemplate.identifier.line;
addErrorMessage(line, column, message); addErrorMessage(line, column, message);
} }
c.accept(this);
} }
} }
@ -83,6 +100,10 @@ unittest
catch (Exception err) // ok catch (Exception err) // ok
{ {
}
catch (shared(Exception) err) // ok
{
} }
catch (Error err) // [warn]: Catching Error or Throwable is almost always a bad idea. 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 (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. catch // [warn]: Catching Error or Throwable is almost always a bad idea.
{ {
} }
} }
}c, sac); }c, sac);

View File

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

View File

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