Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/analysis/helpers.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module analysis.helpers;

import core.exception : AssertError;
import std.string;
import std.traits;
import std.stdio;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
19 changes: 13 additions & 6 deletions src/analysis/useless_assert.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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)
Expand All @@ -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":
Expand All @@ -58,19 +65,19 @@ 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":
if (!token.text.to!real)
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":
Expand Down