mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7556 from ethereum/ice-7550
Check for use of modifiers in invalid contexts
This commit is contained in:
commit
15e39f7d65
@ -524,7 +524,12 @@ void TypeChecker::visitManually(
|
|||||||
_modifier.arguments() ? *_modifier.arguments() : std::vector<ASTPointer<Expression>>();
|
_modifier.arguments() ? *_modifier.arguments() : std::vector<ASTPointer<Expression>>();
|
||||||
for (ASTPointer<Expression> const& argument: arguments)
|
for (ASTPointer<Expression> const& argument: arguments)
|
||||||
argument->accept(*this);
|
argument->accept(*this);
|
||||||
|
|
||||||
|
{
|
||||||
|
m_insideModifierInvocation = true;
|
||||||
|
ScopeGuard resetFlag{[&] () { m_insideModifierInvocation = false; }};
|
||||||
_modifier.name()->accept(*this);
|
_modifier.name()->accept(*this);
|
||||||
|
}
|
||||||
|
|
||||||
auto const* declaration = &dereference(*_modifier.name());
|
auto const* declaration = &dereference(*_modifier.name());
|
||||||
vector<ASTPointer<VariableDeclaration>> emptyParameterList;
|
vector<ASTPointer<VariableDeclaration>> emptyParameterList;
|
||||||
@ -2378,12 +2383,21 @@ bool TypeChecker::visit(Identifier const& _identifier)
|
|||||||
if (_identifier.name() == "sha3" && fType->kind() == FunctionType::Kind::KECCAK256)
|
if (_identifier.name() == "sha3" && fType->kind() == FunctionType::Kind::KECCAK256)
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
_identifier.location(),
|
_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)
|
else if (_identifier.name() == "suicide" && fType->kind() == FunctionType::Kind::Selfdestruct)
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
_identifier.location(),
|
_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<decltype(type)>(_identifier.annotation().type))
|
||||||
|
{
|
||||||
|
m_errorReporter.typeError(
|
||||||
|
_identifier.location(),
|
||||||
|
"Modifier can only be referenced in function headers."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +166,9 @@ private:
|
|||||||
/// Flag indicating whether we are currently inside a StructDefinition.
|
/// Flag indicating whether we are currently inside a StructDefinition.
|
||||||
bool m_insideStruct = false;
|
bool m_insideStruct = false;
|
||||||
|
|
||||||
|
/// Flag indicating whether we are currently inside the invocation of a modifier
|
||||||
|
bool m_insideModifierInvocation = false;
|
||||||
|
|
||||||
langutil::ErrorReporter& m_errorReporter;
|
langutil::ErrorReporter& m_errorReporter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,5 +8,5 @@ contract test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError: (58-62): "sha3" has been deprecated in favour of "keccak256"
|
// TypeError: (58-62): "sha3" has been deprecated in favour of "keccak256".
|
||||||
// TypeError: (101-108): "suicide" has been deprecated in favour of "selfdestruct"
|
// TypeError: (101-108): "suicide" has been deprecated in favour of "selfdestruct".
|
||||||
|
@ -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".
|
||||||
|
@ -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".
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
contract test {
|
||||||
|
modifier mod() { _; }
|
||||||
|
|
||||||
|
function f() public {
|
||||||
|
mod ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (77-80): Modifier can only be referenced in function headers.
|
Loading…
Reference in New Issue
Block a user