Mark the empty version pragma as invalid

This commit is contained in:
Alex Beregszaszi 2020-12-18 15:43:14 +00:00
parent fdbb4d9a8f
commit 8edfa26f0a
4 changed files with 12 additions and 3 deletions

View File

@ -151,6 +151,9 @@ optional<SemVerMatchExpression> SemVerMatchExpressionParser::parse()
{
reset();
if (m_tokens.empty())
return nullopt;
try
{
while (true)

View File

@ -24,6 +24,7 @@
#pragma once
#include <liblangutil/Token.h>
#include <libsolutil/Assertions.h>
#include <string>
#include <optional>
@ -84,9 +85,11 @@ struct SemVerMatchExpression
class SemVerMatchExpressionParser
{
public:
SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _literals):
SemVerMatchExpressionParser(std::vector<Token> _tokens, std::vector<std::string> _literals):
m_tokens(std::move(_tokens)), m_literals(std::move(_literals))
{}
{
solAssert(m_tokens.size() == m_literals.size(), "");
}
/// Returns an expression if it was parseable, or nothing otherwise.
std::optional<SemVerMatchExpression> parse();

View File

@ -204,7 +204,7 @@ ASTPointer<PragmaDirective> Parser::parsePragmaDirective()
nodeFactory.markEndPosition();
expectToken(Token::Semicolon);
if (literals.size() >= 2 && literals[0] == "solidity")
if (literals.size() >= 1 && literals[0] == "solidity")
{
parsePragmaVersion(
nodeFactory.location(),

View File

@ -0,0 +1,3 @@
pragma solidity;
// ----
// ParserError 1684: (0-16): Found version pragma, but failed to parse it. Please ensure there is a trailing semicolon.