From 9c7b1e9c3f606925ba160686214abec4eee8adc9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 23 Feb 2021 10:57:49 +0100 Subject: [PATCH] Detect assignment to function in inline assembly. --- libyul/AsmAnalysis.cpp | 8 +++----- .../inlineAssembly/invalid/assignment_to_function.sol | 10 ++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/invalid/assignment_to_function.sol diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 75428fe5b..fdd4c19ed 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -530,11 +530,9 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT bool found = false; if (Scope::Identifier const* var = m_currentScope->lookup(_variable.name)) { - // Check that it is a variable. - // This can also hold a function, but that is caught by error 6041. - yulAssert(holds_alternative(*var), "Assignment requires variable."); - - if (!m_activeVariables.count(&std::get(*var))) + if (!holds_alternative(*var)) + m_errorReporter.typeError(2657_error, _variable.location, "Assignment requires variable."); + else if (!m_activeVariables.count(&std::get(*var))) m_errorReporter.declarationError( 1133_error, _variable.location, diff --git a/test/libsolidity/syntaxTests/inlineAssembly/invalid/assignment_to_function.sol b/test/libsolidity/syntaxTests/inlineAssembly/invalid/assignment_to_function.sol new file mode 100644 index 000000000..9ce487295 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/invalid/assignment_to_function.sol @@ -0,0 +1,10 @@ +contract C { + function f() public pure { + assembly { + function f() {} + f := 1 + } + } +} +// ---- +// TypeError 2657: (103-104): Assignment requires variable.