Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
### 0.8.32 (unreleased)

Language Features:
* Syntax Checker: Warn about identifiers selected for future promotion to Solidity keywords.
* Yul Analyzer: Warn about identifiers selected for future promotion to Yul keywords.

Compiler Features:

Expand Down
1 change: 1 addition & 0 deletions docs/assembly.rst
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR needs a changelog entry.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should also add a note/warning about the new keywords under Reserved Keywords in the docs.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Solidity language without a compiler change.
pragma solidity >=0.4.16 <0.9.0;

library GetCode {
// This will report a warning - `at` will be promoted to reserved keyword
function at(address addr) public view returns (bytes memory code) {
assembly {
// retrieve the size of the code, this needs assembly
Expand Down
9 changes: 9 additions & 0 deletions docs/units-and-global-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,12 @@ These keywords are reserved in Solidity. They might become part of the syntax in
``mutable``, ``null``, ``of``, ``partial``, ``promise``, ``reference``, ``relocatable``,
``sealed``, ``sizeof``, ``static``, ``supports``, ``switch``, ``typedef``, ``typeof``,
``var``.

.. note::
The following identifiers will become unavailable in the future due to already being part of
the language syntax and thus selected to become Solidity keywords:
``transient``, ``layout``, ``at``, ``error``, ``super``, ``this``.

There are also Yul identifiers which are selected to become keywords in the future:
``leave``, ``basefee``, ``prevrandao``, ``blobbasefee``, ``blobhash``, ``mcopy``, ``tstore``, ``tload``.

34 changes: 34 additions & 0 deletions liblangutil/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,40 @@ bool isYulKeyword(std::string_view const _literal)
return _literal == "leave" || isYulKeyword(keywordByName(_literal));
}

bool isFutureSolidityKeyword(std::string const& _literal)
{
std::set<std::string> const futureSolidityKeywords = {
"transient",
"layout",
"at",
"error",
"super",
"this"
};
return futureSolidityKeywords.contains(_literal);
}

bool isFutureYulKeyword(std::string const& _literal)
{
return _literal == "leave";
}

bool isFutureYulReservedIdentifier(std::string const& _literal)
{
std::set<std::string> futureReservedIdentifier = {
"basefee",
"blobbasefee",
"blobhash",
"clz",
"mcopy",
"memoryguard",
"prevrandao",
"tload",
"tstore",
};
return futureReservedIdentifier.contains(_literal);
}

std::tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal)
{
// Used for `bytesM`, `uintM`, `intM`, `fixedMxN`, `ufixedMxN`.
Expand Down
6 changes: 6 additions & 0 deletions liblangutil/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ namespace TokenTraits

bool isYulKeyword(std::string_view _literal);

bool isFutureSolidityKeyword(std::string const& _literal);

bool isFutureYulKeyword(std::string const& _literal);

bool isFutureYulReservedIdentifier(std::string const& _literal);

Token AssignmentToBinaryOp(Token op);

// @returns the precedence > 0 for binary and compare
Expand Down
14 changes: 14 additions & 0 deletions libsolidity/analysis/NameAndTypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,20 @@ bool DeclarationRegistrationHelper::registerDeclaration(
);
}

if (
TokenTraits::isFutureSolidityKeyword(name) ||
TokenTraits::isFutureYulKeyword(name)
)
_errorReporter.warning(
6335_error,
_declaration.location(),
fmt::format(
"\"{}\" will be promoted to keyword in the next breaking version"
" and will not be allowed as an identifier anymore.",
name
)
);

if (!_container.registerDeclaration(_declaration, _name, _errorLocation, !_declaration.isVisibleInContract() || _inactive, false))
{
SourceLocation firstDeclarationLocation;
Expand Down
1 change: 1 addition & 0 deletions libsolidity/analysis/SyntaxChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ bool SyntaxChecker::visit(ContractDefinition const& _contract)
"Functions are not allowed to have the same name as the contract. "
"If you intend this to be a constructor, use \"constructor(...) { ... }\" to define it."
);

return true;
}

Expand Down
23 changes: 21 additions & 2 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <libyul/ScopeFiller.h>

#include <liblangutil/ErrorReporter.h>
#include <liblangutil/Token.h>

#include <libsolutil/CommonData.h>
#include <libsolutil/StringUtils.h>
Expand Down Expand Up @@ -296,9 +297,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
m_currentScope->insideFunction()
);
for (auto const& variable: _varDecl.variables)
{
expectValidIdentifier(variable.name, nativeLocationOf(variable));
}

if (_varDecl.value)
{
Expand Down Expand Up @@ -745,6 +744,8 @@ void AsmAnalyzer::expectValidIdentifier(YulName _identifier, SourceLocation cons
_location,
fmt::format("The identifier \"{}\" is reserved and can not be used.", label)
);

checkFutureReservedKeywordOrIdentifier(_identifier, _location);
}

bool AsmAnalyzer::validateInstructions(std::string_view _instructionIdentifier, langutil::SourceLocation const& _location)
Expand Down Expand Up @@ -953,3 +954,21 @@ void AsmAnalyzer::validateObjectStructure(langutil::SourceLocation const& _astRo
}
}
}

void AsmAnalyzer::checkFutureReservedKeywordOrIdentifier(YulName _identifier, langutil::SourceLocation const& _location)
{
if (
TokenTraits::isFutureYulKeyword(_identifier.str()) ||
TokenTraits::isFutureYulReservedIdentifier(_identifier.str())
)
m_errorReporter.warning(
5470_error,
_location,
fmt::format(
"\"{}\" will be promoted to reserved Yul {} in the next breaking version "
"and will not be allowed anymore as an identifier.",
_identifier.str(),
(TokenTraits::isFutureYulKeyword(_identifier.str()) ? "keyword" : "identifier")
)
);
}
2 changes: 2 additions & 0 deletions libyul/AsmAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class AsmAnalyzer

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

void checkFutureReservedKeywordOrIdentifier(YulName _identifier, langutil::SourceLocation const& _location);

yul::ExternalIdentifierAccess::Resolver m_resolver;
Scope* m_currentScope = nullptr;
/// Variables that are active at the current point in assembly (as opposed to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Warning: "memoryguard" will be promoted to reserved Yul identifier in the next breaking version and will not be allowed anymore as an identifier.
--> input.sol:10:20:
|
10 | assembly { function memoryguard() {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^

Warning: "memoryguard" will be promoted to reserved Yul identifier in the next breaking version and will not be allowed anymore as an identifier.
--> input.sol:11:31:
|
11 | assembly { function f(memoryguard) {} }
| ^^^^^^^^^^^

Warning: "memoryguard" will be promoted to reserved Yul identifier in the next breaking version and will not be allowed anymore as an identifier.
--> input.sol:12:36:
|
12 | assembly { function f() -> memoryguard {} }
| ^^^^^^^^^^^

Warning: "memoryguard" will be promoted to reserved Yul identifier in the next breaking version and will not be allowed anymore as an identifier.
--> input.sol:13:24:
|
13 | assembly { let memoryguard }
| ^^^^^^^^^^^
2 changes: 1 addition & 1 deletion test/externalTests/zeppelin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function zeppelin_test
const result = await runSuper(args);
result.output.errors = (result.output.errors || []).filter(err => {
if (err.severity === "warning" && err.message.includes("deprecated")) {
if (err.severity === "warning" && (err.message.includes("deprecated") || err.message.includes("promoted"))) {
return false; // suppress this warning
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ contract C {
int constant public transient = 0;
}
// ----
// Warning 6335: (17-50): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ library L {

// ----
// Warning 6162: (251-267): Naming function type parameters is deprecated.
// Warning 6335: (251-267): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (159-173): Data location must be "memory" or "calldata" for parameter in function, but "storage" was given.
// TypeError 6651: (251-267): Data location must be "memory" or "calldata" for parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ contract test {
function f(bytes transient) external;
}
// ----
// Warning 6335: (31-46): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (31-46): Data location must be "memory" or "calldata" for parameter in external function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ contract test {
function f(bytes transient) internal {}
}
// ----
// Warning 6335: (31-46): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (31-46): Data location must be "storage", "memory" or "calldata" for parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ library L {
function i2() external pure returns (uint[] transient) { }
}
// ----
// Warning 6335: (28-44): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (103-119): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (141-157): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (218-234): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (256-272): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (329-345): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (367-383): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (444-460): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (28-44): Data location must be "storage", "memory" or "calldata" for parameter in function, but none was given.
// TypeError 6651: (103-119): Data location must be "storage", "memory" or "calldata" for return parameter in function, but none was given.
// TypeError 6651: (141-157): Data location must be "storage", "memory" or "calldata" for parameter in function, but none was given.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ library test {
function f(bytes transient) external {}
}
// ----
// Warning 6335: (30-45): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (30-45): Data location must be "storage", "memory" or "calldata" for parameter in external function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ library test {
function f(bytes transient) internal pure {}
}
// ----
// Warning 6335: (30-45): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (30-45): Data location must be "storage", "memory" or "calldata" for parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ contract C {
function f(uint[] transient) private pure {}
}
// ----
// Warning 6335: (28-44): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (28-44): Data location must be "storage", "memory" or "calldata" for parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ contract C {
function f() private pure returns (uint[] transient) {}
}
// ----
// Warning 6335: (52-68): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (52-68): Data location must be "storage", "memory" or "calldata" for return parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ contract test {
function f(bytes transient) public;
}
// ----
// Warning 6335: (31-46): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (31-46): Data location must be "memory" or "calldata" for parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ contract C {
function h() public pure returns(uint[] transient) {}
}
// ----
// Warning 6335: (50-66): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (50-66): Data location must be "memory" or "calldata" for return parameter in function, but none was given.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ contract C {
}
// ----
// Warning 6162: (27-41): Naming function type parameters is deprecated.
// Warning 6335: (27-41): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ contract C {
}
}
// ----
// Warning 6335: (61-88): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (90-118): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 2319: (61-88): This declaration shadows a builtin symbol.
// Warning 2319: (90-118): This declaration shadows a builtin symbol.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ contract C {
// ----
// DeclarationError 3726: (17-78): The name "_" is reserved.
// DeclarationError 3726: (84-117): The name "super" is reserved.
// Warning 6335: (84-117): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (123-155): The name "this" is reserved.
// Warning 6335: (123-155): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 2319: (84-117): This declaration shadows a builtin symbol.
// Warning 2319: (123-155): This declaration shadows a builtin symbol.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum error { layout, at }
/// ----
// ----
// Warning 6335: (0-25): "error" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (13-19): "layout" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (21-23): "at" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
4 changes: 4 additions & 0 deletions test/libsolidity/syntaxTests/enums/illegal_names.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ contract C {
}
// ----
// DeclarationError 3726: (0-19): The name "this" is reserved.
// Warning 6335: (0-19): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (20-40): The name "super" is reserved.
// Warning 6335: (20-40): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (41-57): The name "_" is reserved.
// DeclarationError 3726: (72-76): The name "this" is reserved.
// Warning 6335: (72-76): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (82-87): The name "super" is reserved.
// Warning 6335: (82-87): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (93-94): The name "_" is reserved.
// Warning 2319: (0-19): This declaration shadows a builtin symbol.
// Warning 2319: (20-40): This declaration shadows a builtin symbol.
1 change: 1 addition & 0 deletions test/libsolidity/syntaxTests/errors/struct_named_error.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ contract C {
error x;
}
// ----
// Warning 6335: (52-74): "error" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ contract C {
event _();
}
// ----
// Warning 6335: (80-93): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (95-109): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 2319: (80-93): This declaration shadows a builtin symbol.
// Warning 2319: (95-109): This declaration shadows a builtin symbol.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
event this();
event super();
event _();
// ----
// Warning 6335: (66-79): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (80-94): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
2 changes: 2 additions & 0 deletions test/libsolidity/syntaxTests/freeFunctions/illegal_names.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ contract C {
}
// ----
// DeclarationError 3726: (0-18): The name "this" is reserved.
// Warning 6335: (0-18): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (19-38): The name "super" is reserved.
// Warning 6335: (19-38): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (39-54): The name "_" is reserved.
// Warning 2319: (0-18): This declaration shadows a builtin symbol.
// Warning 2319: (19-38): This declaration shadows a builtin symbol.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ contract C {
// ----
// Warning 6162: (27-41): Naming function type parameters is deprecated.
// Warning 6162: (69-85): Naming function type parameters is deprecated.
// Warning 6335: (27-41): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 6335: (69-85): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// TypeError 6651: (69-85): Data location must be "memory" or "calldata" for parameter in function, but none was given.
2 changes: 2 additions & 0 deletions test/libsolidity/syntaxTests/immutable/illegal_names.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ contract C {
}
// ----
// DeclarationError 3726: (17-37): The name "super" is reserved.
// Warning 6335: (17-37): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// DeclarationError 3726: (43-59): The name "_" is reserved.
// DeclarationError 3726: (65-84): The name "this" is reserved.
// Warning 6335: (65-84): "this" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 2319: (17-37): This declaration shadows a builtin symbol.
// Warning 2319: (65-84): This declaration shadows a builtin symbol.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ contract C {
address public immutable transient;
}
// ----
// Warning 6335: (17-51): "transient" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
==== Source: a ====
contract A {}
==== Source: b ====
import {A as layout} from "a";
contract C is layout {}
// ----
// Warning 6335: (a:0-13): "layout" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
==== Source: a ====
uint constant CONST = 10;
==== Source: b ====
import "a" as super;
contract C {
uint x = super.CONST;
}
// ----
// DeclarationError 3726: (b:0-20): The name "super" is reserved.
// Warning 6335: (b:0-20): "super" will be promoted to keyword in the next breaking version and will not be allowed as an identifier anymore.
// Warning 2319: (b:0-20): This declaration shadows a builtin symbol.
Loading