diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index b2f8015c9..009b3613b 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -113,20 +113,30 @@ void SyntaxTest::parseAndAnalyze() void SyntaxTest::filterObtainedErrors() { - string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n"; for (auto const& currentError: filterErrors(compiler().errors(), true)) { int locationStart = -1, locationEnd = -1; string sourceName; if (auto location = boost::get_error_info(*currentError)) { + solAssert(location->source, ""); + sourceName = location->source->name(); + + solAssert(m_sources.count(sourceName) == 1, ""); + int preambleSize = static_cast(location->source->source().size()) - static_cast(m_sources[sourceName].size()); + solAssert(preambleSize >= 0, ""); + // ignore the version & license pragma inserted by the testing tool when calculating locations. - if (location->start >= static_cast(preamble.size())) - locationStart = location->start - static_cast(preamble.size()); - if (location->end >= static_cast(preamble.size())) - locationEnd = location->end - static_cast(preamble.size()); - if (location->source) - sourceName = location->source->name(); + if (location->start != -1) + { + solAssert(location->start >= preambleSize, ""); + locationStart = location->start - preambleSize; + } + if (location->end != -1) + { + solAssert(location->end >= preambleSize, ""); + locationEnd = location->end - preambleSize; + } } m_errorList.emplace_back(SyntaxTestError{ currentError->typeName(), diff --git a/test/libsolidity/syntaxTests/imports/multiple_non_existent_file_names.sol b/test/libsolidity/syntaxTests/imports/multiple_non_existent_file_names.sol new file mode 100644 index 000000000..4172955ab --- /dev/null +++ b/test/libsolidity/syntaxTests/imports/multiple_non_existent_file_names.sol @@ -0,0 +1,10 @@ +import "~~~some-long-unlikely-file-name-12"; +import "~~~some-long-unlikely-file-name-456"; +import "~~~some-long-unlikely-file-name-7890"; +// This test is here to verify that the license/pragma preamble added by the test suite does not +// affect source locations in error messages. Positions in messages below should start at 0 and +// there should be no gaps between the ranges. +// ---- +// ParserError 6275: (0-44): Source "~~~some-long-unlikely-file-name-12" not found: File not supplied initially. +// ParserError 6275: (45-90): Source "~~~some-long-unlikely-file-name-456" not found: File not supplied initially. +// ParserError 6275: (91-137): Source "~~~some-long-unlikely-file-name-7890" not found: File not supplied initially.