fixup! Syntax for custom errors.

This commit is contained in:
chriseth 2021-02-02 16:31:36 +01:00
parent edf3529db6
commit b6183edd18
4 changed files with 16 additions and 0 deletions

View File

@ -192,6 +192,17 @@ void SyntaxChecker::endVisit(ModifierDefinition const& _modifier)
m_placeholderFound = false;
}
bool SyntaxChecker::visit(ErrorDefinition const& _error)
{
if (_error.name() == "Error" || _error.name() == "Panic")
m_errorReporter.syntaxError(
1855_error,
_error.location(),
"The built-in errors \"Error\" and \"Panic\" cannot be re-defined."
);
return true;
}
void SyntaxChecker::checkSingleStatementVariableDeclaration(ASTNode const& _statement)
{
auto varDecl = dynamic_cast<VariableDeclarationStatement const*>(&_statement);

View File

@ -40,6 +40,7 @@ namespace solidity::frontend
* - issues deprecation warning for throw
* - whether the msize instruction is used and the Yul optimizer is enabled at the same time.
* - selection of the ABI coder through pragmas.
* - whether user-defined errors are called Error or Panic.
*/
class SyntaxChecker: private ASTConstVisitor
{
@ -61,6 +62,8 @@ private:
bool visit(ModifierDefinition const& _modifier) override;
void endVisit(ModifierDefinition const& _modifier) override;
bool visit(ErrorDefinition const& _error) override;
/// Reports an error if _statement is a VariableDeclarationStatement.
/// Used by if/while/for to check for single statement variable declarations
/// without a block.

View File

@ -1,3 +1,4 @@
// TODO do we want to disallow this at all?
error Error(uint);
// ----
// SyntaxError 1855: (44-62): The built-in errors "Error" and "Panic" cannot be re-defined.

View File

@ -2,3 +2,4 @@
// TODO I Think the best way would be to have Error in the global scope.
error Panic(bytes2);
// ----
// SyntaxError 1855: (131-151): The built-in errors "Error" and "Panic" cannot be re-defined.