Fix noreturn discard warning (#887)
Fixes https://github.com/dlang-community/D-Scanner/issues/886
This commit is contained in:
parent
e94c4fad77
commit
40235d3f9d
|
@ -37,12 +37,16 @@ private:
|
|||
public:
|
||||
|
||||
const(DSymbol)* void_;
|
||||
const(DSymbol)* noreturn_;
|
||||
|
||||
///
|
||||
this(string fileName, const(Scope)* sc, bool skipTests = false)
|
||||
{
|
||||
super(fileName, sc, skipTests);
|
||||
void_ = sc.getSymbolsByName(internString("void"))[0];
|
||||
auto symbols = sc.getSymbolsByName(internString("noreturn"));
|
||||
if (symbols.length > 0)
|
||||
noreturn_ = symbols[0];
|
||||
}
|
||||
|
||||
override void visit(const(ExpressionStatement) decl)
|
||||
|
@ -85,6 +89,8 @@ public:
|
|||
return;
|
||||
if (sym.type is void_)
|
||||
return;
|
||||
if (noreturn_ && sym.type is noreturn_)
|
||||
return;
|
||||
}
|
||||
|
||||
addErrorMessage(decl.expression.line, decl.expression.column, KEY, MSG);
|
||||
|
@ -109,6 +115,15 @@ unittest
|
|||
}
|
||||
}c, sac);
|
||||
|
||||
assertAnalyzerWarnings(q{
|
||||
alias noreturn = typeof(*null);
|
||||
noreturn fun() { while (1) {} }
|
||||
noreturn main()
|
||||
{
|
||||
fun();
|
||||
}
|
||||
}c, sac);
|
||||
|
||||
assertAnalyzerWarnings(q{
|
||||
int fun() { return 1; }
|
||||
void main()
|
||||
|
|
Loading…
Reference in New Issue