From e2dac9ed397c29bfe426912c28ef2d419b2324c8 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Wed, 7 Mar 2018 16:06:09 +0100 Subject: [PATCH] Set header.isConstructor for old style constructors in parseFunctionHeader as well. --- libsolidity/parsing/Parser.cpp | 16 +++++++++++----- libsolidity/parsing/Parser.h | 6 +++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index e5cc69d89..6ae66eee4 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -332,14 +332,18 @@ StateMutability Parser::parseStateMutability(Token::Value _token) return stateMutability; } -Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers) +Parser::FunctionHeaderParserResult Parser::parseFunctionHeader( + bool _forceEmptyName, + bool _allowModifiers, + ASTString const* _contractName +) { RecursionGuard recursionGuard(*this); FunctionHeaderParserResult result; if (m_scanner->currentToken() == Token::Function) // In case of old style constructors, i.e. functions with the same name as the contract, - // this is set to true later in parseFunctionDefinitionOrFunctionTypeStateVariable. + // this is set to true below. result.isConstructor = false; else if (m_scanner->currentToken() == Token::Identifier && m_scanner->currentLiteral() == "constructor") result.isConstructor = true; @@ -351,6 +355,10 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN result.name = make_shared(); else result.name = expectIdentifierToken(); + + if (!result.name->empty() && _contractName && *result.name == *_contractName) + result.isConstructor = true; + VarDeclParserOptions options; options.allowLocationSpecifier = true; result.parameters = parseParameterList(options); @@ -420,7 +428,7 @@ ASTPointer Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A if (m_scanner->currentCommentLiteral() != "") docstring = make_shared(m_scanner->currentCommentLiteral()); - FunctionHeaderParserResult header = parseFunctionHeader(false, true); + FunctionHeaderParserResult header = parseFunctionHeader(false, true, _contractName); if ( !header.modifiers.empty() || @@ -439,8 +447,6 @@ ASTPointer Parser::parseFunctionDefinitionOrFunctionTypeStateVariable(A } else m_scanner->next(); // just consume the ';' - if (_contractName && *header.name == *_contractName) - header.isConstructor = true; return nodeFactory.createNode( header.name, header.visibility, diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 2d0e52e18..eb120a614 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -74,7 +74,11 @@ private: ASTPointer parseInheritanceSpecifier(); Declaration::Visibility parseVisibilitySpecifier(Token::Value _token); StateMutability parseStateMutability(Token::Value _token); - FunctionHeaderParserResult parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers); + FunctionHeaderParserResult parseFunctionHeader( + bool _forceEmptyName, + bool _allowModifiers, + ASTString const* _contractName = nullptr + ); ASTPointer parseFunctionDefinitionOrFunctionTypeStateVariable(ASTString const* _contractName); ASTPointer parseFunctionDefinition(ASTString const* _contractName); ASTPointer parseStructDefinition();