diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 42b1be500..b5a81336e 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -524,7 +524,12 @@ void TypeChecker::visitManually( _modifier.arguments() ? *_modifier.arguments() : std::vector>(); for (ASTPointer const& argument: arguments) argument->accept(*this); - _modifier.name()->accept(*this); + + { + m_insideModifierInvocation = true; + ScopeGuard resetFlag{[&] () { m_insideModifierInvocation = false; }}; + _modifier.name()->accept(*this); + } auto const* declaration = &dereference(*_modifier.name()); vector> emptyParameterList; @@ -2378,15 +2383,24 @@ bool TypeChecker::visit(Identifier const& _identifier) if (_identifier.name() == "sha3" && fType->kind() == FunctionType::Kind::KECCAK256) m_errorReporter.typeError( _identifier.location(), - "\"sha3\" has been deprecated in favour of \"keccak256\"" + "\"sha3\" has been deprecated in favour of \"keccak256\"." ); else if (_identifier.name() == "suicide" && fType->kind() == FunctionType::Kind::Selfdestruct) m_errorReporter.typeError( _identifier.location(), - "\"suicide\" has been deprecated in favour of \"selfdestruct\"" + "\"suicide\" has been deprecated in favour of \"selfdestruct\"." ); } + if (!m_insideModifierInvocation) + if (ModifierType const* type = dynamic_cast(_identifier.annotation().type)) + { + m_errorReporter.typeError( + _identifier.location(), + "Modifier can only be referenced in function headers." + ); + } + return false; } diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 8f532a89c..003915b2e 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -166,6 +166,9 @@ private: /// Flag indicating whether we are currently inside a StructDefinition. bool m_insideStruct = false; + /// Flag indicating whether we are currently inside the invocation of a modifier + bool m_insideModifierInvocation = false; + langutil::ErrorReporter& m_errorReporter; }; diff --git a/test/libsolidity/syntaxTests/deprecated_functions.sol b/test/libsolidity/syntaxTests/deprecated_functions.sol index c5764e96c..4774de47f 100644 --- a/test/libsolidity/syntaxTests/deprecated_functions.sol +++ b/test/libsolidity/syntaxTests/deprecated_functions.sol @@ -8,5 +8,5 @@ contract test { } } // ---- -// TypeError: (58-62): "sha3" has been deprecated in favour of "keccak256" -// TypeError: (101-108): "suicide" has been deprecated in favour of "selfdestruct" +// TypeError: (58-62): "sha3" has been deprecated in favour of "keccak256". +// TypeError: (101-108): "suicide" has been deprecated in favour of "selfdestruct". diff --git a/test/libsolidity/syntaxTests/globalFunctions/sha3_no_call.sol b/test/libsolidity/syntaxTests/globalFunctions/sha3_no_call.sol index 37b60e5e4..4e3b5fd05 100644 --- a/test/libsolidity/syntaxTests/globalFunctions/sha3_no_call.sol +++ b/test/libsolidity/syntaxTests/globalFunctions/sha3_no_call.sol @@ -5,4 +5,4 @@ contract C } } // ---- -// TypeError: (60-64): "sha3" has been deprecated in favour of "keccak256" +// TypeError: (60-64): "sha3" has been deprecated in favour of "keccak256". diff --git a/test/libsolidity/syntaxTests/globalFunctions/suicide_no_call.sol b/test/libsolidity/syntaxTests/globalFunctions/suicide_no_call.sol index bf3f5ebc8..f243e2f26 100644 --- a/test/libsolidity/syntaxTests/globalFunctions/suicide_no_call.sol +++ b/test/libsolidity/syntaxTests/globalFunctions/suicide_no_call.sol @@ -5,4 +5,4 @@ contract C } } // ---- -// TypeError: (60-67): "suicide" has been deprecated in favour of "selfdestruct" +// TypeError: (60-67): "suicide" has been deprecated in favour of "selfdestruct". diff --git a/test/libsolidity/syntaxTests/modifiers/use_in_invalid_context.sol b/test/libsolidity/syntaxTests/modifiers/use_in_invalid_context.sol new file mode 100644 index 000000000..1dd797ee6 --- /dev/null +++ b/test/libsolidity/syntaxTests/modifiers/use_in_invalid_context.sol @@ -0,0 +1,9 @@ +contract test { + modifier mod() { _; } + + function f() public { + mod ; + } +} +// ---- +// TypeError: (77-80): Modifier can only be referenced in function headers.