diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 9e10b9b20..97033b0dd 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -286,19 +286,19 @@ void TypeChecker::checkContractBaseConstructorArguments(ContractDefinition const { if (FunctionDefinition const* constructor = contract->constructor()) for (auto const& modifier: constructor->modifiers()) - { - auto baseContract = dynamic_cast(&dereference(*modifier->name())); - if (modifier->arguments()) + if (auto baseContract = dynamic_cast(&dereference(*modifier->name()))) { - if (baseContract && baseContract->constructor()) - annotateBaseConstructorArguments(_contract, baseContract->constructor(), modifier.get()); + if (modifier->arguments()) + { + if (baseContract->constructor()) + annotateBaseConstructorArguments(_contract, baseContract->constructor(), modifier.get()); + } + else + m_errorReporter.declarationError( + modifier->location(), + "Modifier-style base constructor call without arguments." + ); } - else - m_errorReporter.declarationError( - modifier->location(), - "Modifier-style base constructor call without arguments." - ); - } for (ASTPointer const& base: contract->baseContracts()) { diff --git a/test/libsolidity/syntaxTests/inheritance/modifiers_in_constructor_context.sol b/test/libsolidity/syntaxTests/inheritance/modifiers_in_constructor_context.sol new file mode 100644 index 000000000..d8ce0e488 --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/modifiers_in_constructor_context.sol @@ -0,0 +1,9 @@ +// This generated an invalid warning on m1 in some compiler versions. +contract A { + constructor() m1 public { } + modifier m1 { _; } +} +contract B is A { + modifier m2 { _; } + constructor() A() m1 m2 public { } +}