diff --git a/liblangutil/SemVerHandler.cpp b/liblangutil/SemVerHandler.cpp index 83f526113..44014e50f 100644 --- a/liblangutil/SemVerHandler.cpp +++ b/liblangutil/SemVerHandler.cpp @@ -208,7 +208,10 @@ void SemVerMatchExpressionParser::parseMatchExpression() range.components.push_back(parseMatchComponent()); if (currentToken() == Token::Sub) { - if (containPrefixingToken()) + nextToken(); + range.components.push_back(parseMatchComponent()); + + if (TokenTraits::isPragmaOp(range.components[0].prefix) || TokenTraits::isPragmaOp(range.components[1].prefix)) { solThrow( SemVerError, @@ -217,8 +220,6 @@ void SemVerMatchExpressionParser::parseMatchExpression() } range.components[0].prefix = Token::GreaterThanOrEqual; - nextToken(); - range.components.push_back(parseMatchComponent()); range.components[1].prefix = Token::LessThanOrEqual; } else @@ -332,11 +333,3 @@ void SemVerMatchExpressionParser::nextToken() ++m_pos; m_posInside = 0; } - -bool SemVerMatchExpressionParser::containPrefixingToken() const -{ - if (std::find_if(m_tokens.begin(), m_tokens.end(), TokenTraits::isPragmaOp) != m_tokens.end()) - return true; - else - return false; -} diff --git a/liblangutil/SemVerHandler.h b/liblangutil/SemVerHandler.h index 26ddead6a..cf344502e 100644 --- a/liblangutil/SemVerHandler.h +++ b/liblangutil/SemVerHandler.h @@ -102,7 +102,6 @@ private: char nextChar(); Token currentToken() const; void nextToken(); - bool containPrefixingToken() const; std::vector m_tokens; std::vector m_literals; diff --git a/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_first.sol b/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_first.sol new file mode 100644 index 000000000..35bd89afa --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_first.sol @@ -0,0 +1,3 @@ +pragma solidity <0.8.17 - 0.8.20; +// ---- +// ParserError 1684: (0-33): Invalid version pragma. You cannot use operators (<, <=, >=, >, ^) with version ranges (-). \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_second.sol b/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_second.sol new file mode 100644 index 000000000..5bb8995c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_second.sol @@ -0,0 +1,3 @@ +pragma solidity 0.8.17 - >0.8.20; +// ---- +// ParserError 1684: (0-33): Invalid version pragma. You cannot use operators (<, <=, >=, >, ^) with version ranges (-). \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_two_ranges.sol b/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_two_ranges.sol new file mode 100644 index 000000000..67533547f --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/invalid_range_operator_range_two_ranges.sol @@ -0,0 +1,3 @@ +pragma solidity 0.8.14 || 0.8.17 - >0.8.20; +// ---- +// ParserError 1684: (0-43): Invalid version pragma. You cannot use operators (<, <=, >=, >, ^) with version ranges (-). diff --git a/test/libsolidity/syntaxTests/pragma/valid_range_operator.sol b/test/libsolidity/syntaxTests/pragma/valid_range_operator.sol new file mode 100644 index 000000000..594d6d32b --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/valid_range_operator.sol @@ -0,0 +1,2 @@ +pragma solidity 0.8.17 - 0.8.20; +// ---- diff --git a/test/libsolidity/syntaxTests/pragma/valid_range_operator_two_ranges.sol b/test/libsolidity/syntaxTests/pragma/valid_range_operator_two_ranges.sol new file mode 100644 index 000000000..22b7fa356 --- /dev/null +++ b/test/libsolidity/syntaxTests/pragma/valid_range_operator_two_ranges.sol @@ -0,0 +1,2 @@ +pragma solidity <0.8.15 || 0.8.17 - 0.8.20; +// ----