Skip to content

Commit d9f5625

Browse files
Warning for yul future reserved keywords
1 parent fd12c2c commit d9f5625

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

libyul/AsmAnalysis.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
298298
for (auto const& variable: _varDecl.variables)
299299
{
300300
expectValidIdentifier(variable.name, nativeLocationOf(variable));
301+
checkFutureReservedKeyword(variable.name, nativeLocationOf(variable));
301302
}
302303

303304
if (_varDecl.value)
@@ -326,6 +327,7 @@ void AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
326327
{
327328
yulAssert(!_funDef.name.empty());
328329
expectValidIdentifier(_funDef.name, nativeLocationOf(_funDef));
330+
checkFutureReservedKeyword(_funDef.name, nativeLocationOf(_funDef));
329331
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
330332
yulAssert(virtualBlock, "");
331333
Scope& varScope = scope(virtualBlock);
@@ -951,3 +953,30 @@ void AsmAnalyzer::validateObjectStructure(langutil::SourceLocation const& _astRo
951953
}
952954
}
953955
}
956+
957+
void AsmAnalyzer::checkFutureReservedKeyword(YulName _identifier, langutil::SourceLocation const& _location)
958+
{
959+
std::set<std::string> futureReservedKeywords{"leave"};
960+
if (m_evmVersion < langutil::EVMVersion::london())
961+
futureReservedKeywords.insert("basefee");
962+
if (m_evmVersion < langutil::EVMVersion::paris())
963+
futureReservedKeywords.insert("prevrandao");
964+
if (m_evmVersion < langutil::EVMVersion::cancun())
965+
{
966+
futureReservedKeywords.insert("blobbasefee");
967+
futureReservedKeywords.insert("blobhash");
968+
futureReservedKeywords.insert("mcopy");
969+
futureReservedKeywords.insert("tstore");
970+
futureReservedKeywords.insert("tload");
971+
}
972+
if (futureReservedKeywords.count(_identifier.str()))
973+
m_errorReporter.warning(
974+
5470_error,
975+
_location,
976+
fmt::format(
977+
"\"{}\" will be promoted to reserved keyword in the next breaking version "
978+
"and will not be allowed anymore as an identifier.",
979+
_identifier.str()
980+
)
981+
);
982+
}

libyul/AsmAnalysis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class AsmAnalyzer
128128

129129
void validateObjectStructure(langutil::SourceLocation const& _astRootLocation);
130130

131+
void checkFutureReservedKeyword(YulName _identifier, langutil::SourceLocation const& _location);
132+
131133
yul::ExternalIdentifierAccess::Resolver m_resolver;
132134
Scope* m_currentScope = nullptr;
133135
/// Variables that are active at the current point in assembly (as opposed to

0 commit comments

Comments
 (0)