Skip to content

Commit d0f575a

Browse files
Warning for yul future reserved keywords
1 parent 1445742 commit d0f575a

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);
@@ -953,3 +955,30 @@ void AsmAnalyzer::validateObjectStructure(langutil::SourceLocation const& _astRo
953955
}
954956
}
955957
}
958+
959+
void AsmAnalyzer::checkFutureReservedKeyword(YulName _identifier, langutil::SourceLocation const& _location)
960+
{
961+
std::set<std::string> futureReservedKeywords{"leave"};
962+
if (m_evmVersion < langutil::EVMVersion::london())
963+
futureReservedKeywords.insert("basefee");
964+
if (m_evmVersion < langutil::EVMVersion::paris())
965+
futureReservedKeywords.insert("prevrandao");
966+
if (m_evmVersion < langutil::EVMVersion::cancun())
967+
{
968+
futureReservedKeywords.insert("blobbasefee");
969+
futureReservedKeywords.insert("blobhash");
970+
futureReservedKeywords.insert("mcopy");
971+
futureReservedKeywords.insert("tstore");
972+
futureReservedKeywords.insert("tload");
973+
}
974+
if (futureReservedKeywords.count(_identifier.str()))
975+
m_errorReporter.warning(
976+
5470_error,
977+
_location,
978+
fmt::format(
979+
"\"{}\" will be promoted to reserved keyword in the next breaking version "
980+
"and will not be allowed anymore as an identifier.",
981+
_identifier.str()
982+
)
983+
);
984+
}

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)