diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 0885cc530..80167e3f4 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -509,6 +509,33 @@ bool DeclarationRegistrationHelper::registerDeclaration( // We use "invisible" for both inactive variables in blocks and for members invisible in contracts. // They cannot both be true at the same time. solAssert(!(_inactive && !_declaration.isVisibleInContract()), ""); + + static set illegalNames{"_", "super", "this"}; + + if (illegalNames.count(name)) + { + auto isPublicFunctionOrEvent = [](Declaration const* _d) -> bool + { + if (auto functionDefinition = dynamic_cast(_d)) + { + if (!functionDefinition->isFree() && functionDefinition->isPublic()) + return true; + } + else if (dynamic_cast(_d)) + return true; + + return false; + }; + + // We allow an exception for public functions or events. + if (!isPublicFunctionOrEvent(&_declaration)) + _errorReporter.declarationError( + 3726_error, + *_errorLocation, + "The name \"" + name + "\" is reserved." + ); + } + if (!_container.registerDeclaration(_declaration, _name, _errorLocation, !_declaration.isVisibleInContract() || _inactive, false)) { SourceLocation firstDeclarationLocation; diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index 0560957d7..3cdb6245c 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -380,4 +380,11 @@ void ReferencesResolver::validateYulIdentifierName(yul::YulString _name, SourceL _location, "User-defined identifiers in inline assembly cannot contain '.'." ); + + if (set{"this", "super", "_"}.count(_name.str())) + m_errorReporter.declarationError( + 4113_error, + _location, + "The identifier name \"" + _name.str() + "\" is reserved." + ); }