Fix deprecations (#458)

* Properly import core.exception in analysis/helpers
* Remove the old std.string.removechars from useless_assert
This commit is contained in:
Sebastian Wilzbach 2017-06-15 13:18:17 +02:00 committed by Petar Kirov
parent 764921634e
commit cf3d702720
2 changed files with 17 additions and 9 deletions

View File

@ -5,6 +5,7 @@
module analysis.helpers;
import core.exception : AssertError;
import std.string;
import std.traits;
import std.stdio;
@ -107,14 +108,14 @@ void assertAnalyzerWarnings(string code, const StaticAnalysisConfig config,
{
immutable string errors = "Expected warning:\n%s\nFrom source code at (%s:?):\n%s".format(messages[lineNo],
lineNo, codeLines[lineNo - line]);
throw new core.exception.AssertError(errors, file, lineNo);
throw new AssertError(errors, file, lineNo);
}
// Different warning
else if (warnings[lineNo] != messages[lineNo])
{
immutable string errors = "Expected warning:\n%s\nBut was:\n%s\nFrom source code at (%s:?):\n%s".format(
messages[lineNo], warnings[lineNo], lineNo, codeLines[lineNo - line]);
throw new core.exception.AssertError(errors, file, lineNo);
throw new AssertError(errors, file, lineNo);
}
}
@ -132,6 +133,6 @@ void assertAnalyzerWarnings(string code, const StaticAnalysisConfig config,
if (unexpectedWarnings.length)
{
immutable string message = "Unexpected warnings:\n" ~ unexpectedWarnings.join("\n");
throw new core.exception.AssertError(message, file, line);
throw new AssertError(message, file, line);
}
}

View File

@ -12,6 +12,14 @@ import dparse.lexer;
import std.stdio;
auto filterChars(string chars, S)(S str)
{
import std.algorithm.comparison : among;
import std.algorithm.iteration : filter;
import std.meta : aliasSeqOf;
return str.filter!(c => !c.among(aliasSeqOf!chars));
}
/**
* Checks for asserts that always succeed
*/
@ -28,7 +36,6 @@ class UselessAssertCheck : BaseAnalyzer
override void visit(const AssertExpression ae)
{
import std.conv : to;
import std.string : removechars;
UnaryExpression unary = cast(UnaryExpression) ae.assertion;
if (unary is null)
@ -42,11 +49,11 @@ class UselessAssertCheck : BaseAnalyzer
if (!skipSwitch) switch (token.type)
{
case tok!"doubleLiteral":
if (!token.text.removechars("Ll").to!double)
if (!token.text.filterChars!"Ll".to!double)
return;
break;
case tok!"floatLiteral":
if (!token.text.removechars("Ff").to!float)
if (!token.text.filterChars!"Ff".to!float)
return;
break;
case tok!"idoubleLiteral":
@ -58,7 +65,7 @@ class UselessAssertCheck : BaseAnalyzer
return;
break;
case tok!"longLiteral":
if (!token.text.removechars("Ll").to!long)
if (!token.text.filterChars!"Ll".to!long)
return;
break;
case tok!"realLiteral":
@ -66,11 +73,11 @@ class UselessAssertCheck : BaseAnalyzer
return;
break;
case tok!"uintLiteral":
if (!token.text.removechars("Uu").to!uint)
if (!token.text.filterChars!"Uu".to!uint)
return;
break;
case tok!"ulongLiteral":
if (!token.text.removechars("UuLl").to!ulong)
if (!token.text.filterChars!"UuLl".to!ulong)
return;
break;
case tok!"characterLiteral":