Skip to content

Commit

Permalink
Fixes wrong source location when reporting pragma solidity version co…
Browse files Browse the repository at this point in the history
…nflicts.
  • Loading branch information
christianparpart committed Mar 20, 2019
1 parent 556d11d commit bb28c8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class Parser::ASTNodeFactory
return make_shared<NodeType>(m_location, std::forward<Args>(_args)...);
}

SourceLocation const& location() const noexcept { return m_location; }

private:
Parser const& m_parser;
SourceLocation m_location;
Expand Down Expand Up @@ -108,14 +110,15 @@ ASTPointer<SourceUnit> Parser::parse(shared_ptr<Scanner> const& _scanner)
}
}

void Parser::parsePragmaVersion(vector<Token> const& tokens, vector<string> const& literals)
void Parser::parsePragmaVersion(SourceLocation const& _location, vector<Token> const& _tokens, vector<string> const& _literals)
{
SemVerMatchExpressionParser parser(tokens, literals);
SemVerMatchExpressionParser parser(_tokens, _literals);
auto matchExpression = parser.parse();
static SemVerVersion const currentVersion{string(VersionString)};
// FIXME: only match for major version incompatibility
if (!matchExpression.matches(currentVersion))
fatalParserError(
m_errorReporter.fatalParserError(
_location,
"Source file requires different compiler version (current compiler is " +
string(VersionString) + " - note that nightly builds are considered to be "
"strictly less than the released version"
Expand Down Expand Up @@ -154,6 +157,7 @@ ASTPointer<PragmaDirective> Parser::parsePragmaDirective()
if (literals.size() >= 2 && literals[0] == "solidity")
{
parsePragmaVersion(
nodeFactory.location(),
vector<Token>(tokens.begin() + 1, tokens.end()),
vector<string>(literals.begin() + 1, literals.end())
);
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/parsing/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Parser: public langutil::ParserBase

///@{
///@name Parsing functions for the AST nodes
void parsePragmaVersion(std::vector<Token> const& tokens, std::vector<std::string> const& literals);
void parsePragmaVersion(langutil::SourceLocation const& _location, std::vector<Token> const& _tokens, std::vector<std::string> const& _literals);
ASTPointer<PragmaDirective> parsePragmaDirective();
ASTPointer<ImportDirective> parseImportDirective();
ContractDefinition::ContractKind parseContractKind();
Expand Down

0 comments on commit bb28c8a

Please sign in to comment.