From 6d289783b41109b445fec924354580a79b65a94a Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 16 Mar 2018 11:02:35 +0100 Subject: Fix state variable parsing. --- libsolidity/parsing/Parser.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index 18ef740a..bdb46ad6 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -380,6 +380,14 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( { if (result.visibility != Declaration::Visibility::Default) { + // There is the special case of a public state variable of function type. + // Detect this and return early. + if ( + (result.visibility == Declaration::Visibility::External || result.visibility == Declaration::Visibility::Internal) && + result.modifiers.empty() && + result.name->empty() + ) + break; parserError(string( "Visibility already specified as \"" + Declaration::visibilityToString(result.visibility) + -- cgit v1.2.3 From 2ad1acaf721072d27783d586048d6377be6c3f99 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 16 Mar 2018 12:39:30 +0100 Subject: Warn if modifiers are applied to functions without implementation. --- libsolidity/parsing/Parser.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index bdb46ad6..ea092a74 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -365,12 +365,12 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( Token::Value token = m_scanner->currentToken(); if (_allowModifiers && token == Token::Identifier) { - // This can either be a modifier (function declaration) or the name of the - // variable (function type name plus variable). - if ( + // If the name is empty, then this can either be a modifier (fallback function declaration) + // or the name of the state variable (function type name plus variable). + if (result.name->empty() && ( m_scanner->peekNextToken() == Token::Semicolon || m_scanner->peekNextToken() == Token::Assign - ) + )) // Variable declaration, break here. break; else -- cgit v1.2.3 From b5a696ad48780bf0614eef2a737a2e89963d4640 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 11 Apr 2018 17:44:44 +0200 Subject: Properly cope with constructor headers. --- libsolidity/parsing/Parser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index ea092a74..2d8ca7d3 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -365,9 +365,10 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( Token::Value token = m_scanner->currentToken(); if (_allowModifiers && token == Token::Identifier) { - // If the name is empty, then this can either be a modifier (fallback function declaration) + // If the name is empty (and this is not a constructor), + // then this can either be a modifier (fallback function declaration) // or the name of the state variable (function type name plus variable). - if (result.name->empty() && ( + if ((result.name->empty() && !result.isConstructor) && ( m_scanner->peekNextToken() == Token::Semicolon || m_scanner->peekNextToken() == Token::Assign )) @@ -385,7 +386,7 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( if ( (result.visibility == Declaration::Visibility::External || result.visibility == Declaration::Visibility::Internal) && result.modifiers.empty() && - result.name->empty() + (result.name->empty() && !result.isConstructor) ) break; parserError(string( @@ -437,6 +438,7 @@ ASTPointer Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A FunctionHeaderParserResult header = parseFunctionHeader(false, true, _contractName); if ( + header.isConstructor || !header.modifiers.empty() || !header.name->empty() || m_scanner->currentToken() == Token::Semicolon || @@ -802,6 +804,7 @@ ASTPointer Parser::parseFunctionType() RecursionGuard recursionGuard(*this); ASTNodeFactory nodeFactory(*this); FunctionHeaderParserResult header = parseFunctionHeader(true, false); + solAssert(!header.isConstructor, "Tried to parse type as constructor."); return nodeFactory.createNode( header.parameters, header.returnParameters, -- cgit v1.2.3