From cfb6dfc35ecc52b6e9f93db6b4b4b1ef40a2ba03 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 9 Aug 2016 02:25:07 +0100 Subject: [PATCH 1/2] Introduce isReservedKeyword() --- libsolidity/parsing/Token.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index cc85b6108..6c2309cb5 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -291,6 +291,7 @@ public: static bool isLocationSpecifier(Value op) { return op == Memory || op == Storage; } static bool isEtherSubdenomination(Value op) { return op == SubWei || op == SubSzabo || op == SubFinney || op == SubEther; } static bool isTimeSubdenomination(Value op) { return op == SubSecond || op == SubMinute || op == SubHour || op == SubDay || op == SubWeek || op == SubYear; } + static bool isReservedKeyword(Value op) { return (Abstract <= op && op <= TypeOf); } // @returns a string corresponding to the JS token string // (.e., "<" for the token LT) or NULL if the token doesn't From a13c5b315705dffde48ef46b8ed1208e3aa32989 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 6 Sep 2016 02:22:02 +0100 Subject: [PATCH 2/2] Raise proper error on reserved keywords --- libsolidity/parsing/ParserBase.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libsolidity/parsing/ParserBase.cpp b/libsolidity/parsing/ParserBase.cpp index 71085a4d0..2abf58ccb 100644 --- a/libsolidity/parsing/ParserBase.cpp +++ b/libsolidity/parsing/ParserBase.cpp @@ -47,7 +47,17 @@ void ParserBase::expectToken(Token::Value _value) Token::Value tok = m_scanner->currentToken(); if (tok != _value) { - if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting + if (Token::isReservedKeyword(tok)) + { + fatalParserError( + string("Expected token ") + + string(Token::name(_value)) + + string(" got reserved keyword '") + + string(Token::name(tok)) + + string("'") + ); + } + else if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting { ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); fatalParserError(