diff --git a/Changelog.md b/Changelog.md index 5cacceba9..c41bf5944 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,7 +13,7 @@ Breaking changes: Language Features: * Yul: Disallow EVM instruction `pc()`. - + * Yul: Disallow consecutive and trailing dots in identifiers. Leading dots were already disallowed. Compiler Features: diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index db35c8dc6..1d2c9a40f 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -197,7 +197,10 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl) m_currentScope->insideFunction() ); for (auto const& variable: _varDecl.variables) + { + expectValidIdentifier(variable.name, variable.location); expectValidType(variable.type, variable.location); + } if (_varDecl.value) { @@ -237,11 +240,13 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl) void AsmAnalyzer::operator()(FunctionDefinition const& _funDef) { yulAssert(!_funDef.name.empty(), ""); + expectValidIdentifier(_funDef.name, _funDef.location); Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get(); yulAssert(virtualBlock, ""); Scope& varScope = scope(virtualBlock); for (auto const& var: _funDef.parameters + _funDef.returnVariables) { + expectValidIdentifier(var.name, var.location); expectValidType(var.type, var.location); m_activeVariables.insert(&std::get(varScope.identifiers.at(var.name))); } @@ -517,6 +522,26 @@ Scope& AsmAnalyzer::scope(Block const* _block) return *scopePtr; } +void AsmAnalyzer::expectValidIdentifier(YulString _identifier, SourceLocation const& _location) +{ + // NOTE: the leading dot case is handled by the parser not allowing it. + + if (boost::ends_with(_identifier.str(), ".")) + m_errorReporter.syntaxError( + 3384_error, + _location, + "\"" + _identifier.str() + "\" is not a valid identifier (ends with a dot)." + ); + + if (_identifier.str().find("..") != std::string::npos) + m_errorReporter.syntaxError( + 7771_error, + _location, + "\"" + _identifier.str() + "\" is not a valid identifier (contains consecutive dots)." + ); + +} + void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location) { if (!m_dialect.types.count(_type)) diff --git a/libyul/AsmAnalysis.h b/libyul/AsmAnalysis.h index e0a751b13..345ecab6b 100644 --- a/libyul/AsmAnalysis.h +++ b/libyul/AsmAnalysis.h @@ -108,6 +108,7 @@ private: void checkAssignment(Identifier const& _variable, YulString _valueType); Scope& scope(Block const* _block); + void expectValidIdentifier(YulString _identifier, langutil::SourceLocation const& _location); void expectValidType(YulString _type, langutil::SourceLocation const& _location); void expectType(YulString _expectedType, YulString _givenType, langutil::SourceLocation const& _location);