From 0acd33f48ba58dad5a24254b437ad1eab382ad36 Mon Sep 17 00:00:00 2001 From: sinkuu Date: Wed, 9 Jul 2014 18:10:50 +0900 Subject: [PATCH] Fix PokemonExceptionCheck causes segfault on nested attributes --- analysis/pokemon.d | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/analysis/pokemon.d b/analysis/pokemon.d index 640f0cb..3868c28 100644 --- a/analysis/pokemon.d +++ b/analysis/pokemon.d @@ -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);