From 03f75d55d6f734458e9d4abd9f2686b65de01de6 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 15 Jun 2017 00:30:56 +0200 Subject: [PATCH 1/4] Properly import core.exception in analysis/helpers --- src/analysis/helpers.d | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/analysis/helpers.d b/src/analysis/helpers.d index f609d660..5312ff90 100644 --- a/src/analysis/helpers.d +++ b/src/analysis/helpers.d @@ -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); } } From 9c368214eac5406978d213103d591b0c18a514fa Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 15 Jun 2017 00:38:30 +0200 Subject: [PATCH 2/4] Remove the old std.string.removechars from useless_assert --- src/analysis/useless_assert.d | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/analysis/useless_assert.d b/src/analysis/useless_assert.d index 6ea13233..4bac45d0 100644 --- a/src/analysis/useless_assert.d +++ b/src/analysis/useless_assert.d @@ -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": From a617e36b0cbc90bf4022c0fac9dc972b3a0d5154 Mon Sep 17 00:00:00 2001 From: Petar Kirov Date: Thu, 15 Jun 2017 12:41:34 +0300 Subject: [PATCH 3/4] Fix whitespace --- src/analysis/useless_assert.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/analysis/useless_assert.d b/src/analysis/useless_assert.d index 4bac45d0..75c2e658 100644 --- a/src/analysis/useless_assert.d +++ b/src/analysis/useless_assert.d @@ -14,10 +14,10 @@ import std.stdio; auto filterChars(string chars, S)(S str) { - import std.algorithm.comparison : among; + import std.algorithm.comparison : among; import std.algorithm.iteration : filter; import std.meta : aliasSeqOf; - return str.filter!(c => !c.among(aliasSeqOf!chars)); + return str.filter!(c => !c.among(aliasSeqOf!chars)); } /** From 8b711c5a4e3754dd67ef38912ef3906cb944b40a Mon Sep 17 00:00:00 2001 From: Petar Kirov Date: Thu, 15 Jun 2017 12:43:06 +0300 Subject: [PATCH 4/4] Ah this should be tabs, not spaces --- src/analysis/useless_assert.d | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/analysis/useless_assert.d b/src/analysis/useless_assert.d index 75c2e658..ad61adae 100644 --- a/src/analysis/useless_assert.d +++ b/src/analysis/useless_assert.d @@ -14,10 +14,10 @@ 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)); + import std.algorithm.comparison : among; + import std.algorithm.iteration : filter; + import std.meta : aliasSeqOf; + return str.filter!(c => !c.among(aliasSeqOf!chars)); } /**