Skip to content

Commit 5f73cfc

Browse files
Warning about Solidity future keywords
1 parent 78627e0 commit 5f73cfc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

libsolidity/analysis/SyntaxChecker.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ bool SyntaxChecker::visit(ContractDefinition const& _contract)
391391
"Functions are not allowed to have the same name as the contract. "
392392
"If you intend this to be a constructor, use \"constructor(...) { ... }\" to define it."
393393
);
394+
395+
checkFutureKeyword(_contract);
396+
394397
return true;
395398
}
396399

@@ -477,6 +480,8 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
477480
else if (!_function.isImplemented() && !_function.modifiers().empty())
478481
m_errorReporter.syntaxError(2668_error, _function.location(), "Functions without implementation cannot have modifiers.");
479482

483+
checkFutureKeyword(_function);
484+
480485
return true;
481486
}
482487

@@ -508,5 +513,31 @@ bool SyntaxChecker::visitNode(ASTNode const& _node)
508513
solAssert(m_sourceUnit);
509514
solAssert(m_sourceUnit->experimentalSolidity());
510515
}
516+
auto const* declaration = dynamic_cast<Declaration const*>(&_node);
517+
if (declaration)
518+
checkFutureKeyword(*declaration);
511519
return ASTConstVisitor::visitNode(_node);
512520
}
521+
522+
523+
void SyntaxChecker::checkFutureKeyword(Declaration const& _declaration)
524+
{
525+
std::set<ASTString> const futureKeywords = {
526+
"transient",
527+
"layout",
528+
"at",
529+
"error",
530+
"super",
531+
"this"
532+
};
533+
if (futureKeywords.count(_declaration.name()))
534+
m_errorReporter.warning(
535+
6335_error,
536+
_declaration.location(),
537+
fmt::format(
538+
"\"{}\" will be promoted to reserved keyword in the next breaking version"
539+
" and will not be allowed as an identifier anymore.",
540+
_declaration.name()
541+
)
542+
);
543+
}

libsolidity/analysis/SyntaxChecker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class SyntaxChecker: private ASTConstVisitor
6666
/// without a block.
6767
void checkSingleStatementVariableDeclaration(ASTNode const& _statement);
6868

69+
/// Reports a warning if the declaration name is scheduled to be
70+
/// promoted to a keyword in the near future.
71+
void checkFutureKeyword(Declaration const& _declaration);
72+
6973
bool visit(IfStatement const& _ifStatement) override;
7074
bool visit(WhileStatement const& _whileStatement) override;
7175
void endVisit(WhileStatement const& _whileStatement) override;

0 commit comments

Comments
 (0)