mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9306 from ethereum/yul-restrict-dot
[BREAKING] Restrict dots in Yul identifiers
This commit is contained in:
commit
5cfb929e49
@ -13,7 +13,7 @@ Breaking changes:
|
|||||||
|
|
||||||
Language Features:
|
Language Features:
|
||||||
* Yul: Disallow EVM instruction `pc()`.
|
* Yul: Disallow EVM instruction `pc()`.
|
||||||
|
* Yul: Disallow consecutive and trailing dots in identifiers. Leading dots were already disallowed.
|
||||||
|
|
||||||
Compiler Features:
|
Compiler Features:
|
||||||
|
|
||||||
|
@ -197,7 +197,10 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
|||||||
m_currentScope->insideFunction()
|
m_currentScope->insideFunction()
|
||||||
);
|
);
|
||||||
for (auto const& variable: _varDecl.variables)
|
for (auto const& variable: _varDecl.variables)
|
||||||
|
{
|
||||||
|
expectValidIdentifier(variable.name, variable.location);
|
||||||
expectValidType(variable.type, variable.location);
|
expectValidType(variable.type, variable.location);
|
||||||
|
}
|
||||||
|
|
||||||
if (_varDecl.value)
|
if (_varDecl.value)
|
||||||
{
|
{
|
||||||
@ -237,11 +240,13 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
|||||||
void AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
|
void AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
|
||||||
{
|
{
|
||||||
yulAssert(!_funDef.name.empty(), "");
|
yulAssert(!_funDef.name.empty(), "");
|
||||||
|
expectValidIdentifier(_funDef.name, _funDef.location);
|
||||||
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
|
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
|
||||||
yulAssert(virtualBlock, "");
|
yulAssert(virtualBlock, "");
|
||||||
Scope& varScope = scope(virtualBlock);
|
Scope& varScope = scope(virtualBlock);
|
||||||
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
|
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
|
||||||
{
|
{
|
||||||
|
expectValidIdentifier(var.name, var.location);
|
||||||
expectValidType(var.type, var.location);
|
expectValidType(var.type, var.location);
|
||||||
m_activeVariables.insert(&std::get<Scope::Variable>(varScope.identifiers.at(var.name)));
|
m_activeVariables.insert(&std::get<Scope::Variable>(varScope.identifiers.at(var.name)));
|
||||||
}
|
}
|
||||||
@ -517,6 +522,26 @@ Scope& AsmAnalyzer::scope(Block const* _block)
|
|||||||
return *scopePtr;
|
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)
|
void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location)
|
||||||
{
|
{
|
||||||
if (!m_dialect.types.count(_type))
|
if (!m_dialect.types.count(_type))
|
||||||
|
@ -108,6 +108,7 @@ private:
|
|||||||
void checkAssignment(Identifier const& _variable, YulString _valueType);
|
void checkAssignment(Identifier const& _variable, YulString _valueType);
|
||||||
|
|
||||||
Scope& scope(Block const* _block);
|
Scope& scope(Block const* _block);
|
||||||
|
void expectValidIdentifier(YulString _identifier, langutil::SourceLocation const& _location);
|
||||||
void expectValidType(YulString _type, langutil::SourceLocation const& _location);
|
void expectValidType(YulString _type, langutil::SourceLocation const& _location);
|
||||||
void expectType(YulString _expectedType, YulString _givenType, langutil::SourceLocation const& _location);
|
void expectType(YulString _expectedType, YulString _givenType, langutil::SourceLocation const& _location);
|
||||||
|
|
||||||
|
@ -4,3 +4,9 @@
|
|||||||
_...(a...)
|
_...(a...)
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 3384: (6-27): "_..." is not a valid identifier (ends with a dot).
|
||||||
|
// SyntaxError 7771: (6-27): "_..." is not a valid identifier (contains consecutive dots).
|
||||||
|
// SyntaxError 3384: (20-23): "$.." is not a valid identifier (ends with a dot).
|
||||||
|
// SyntaxError 7771: (20-23): "$.." is not a valid identifier (contains consecutive dots).
|
||||||
|
// SyntaxError 3384: (36-40): "a..." is not a valid identifier (ends with a dot).
|
||||||
|
// SyntaxError 7771: (36-40): "a..." is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x..y() {}
|
function x..y() {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (6-24): "x..y" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x(a..b) {}
|
function x(a..b) {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (17-21): "a..b" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x() -> a..b {}
|
function x() -> a..b {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (22-26): "a..b" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
let a..b := 1
|
let a..b := 1
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (10-14): "a..b" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x...y() {}
|
function x...y() {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (6-25): "x...y" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x(a...b) {}
|
function x(a...b) {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (17-22): "a...b" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x() -> a...b {}
|
function x() -> a...b {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (22-27): "a...b" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
let a...b := 1
|
let a...b := 1
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 7771: (10-15): "a...b" is not a valid identifier (contains consecutive dots).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x.() {}
|
function x.() {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 3384: (6-22): "x." is not a valid identifier (ends with a dot).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x(a.) {}
|
function x(a.) {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 3384: (17-19): "a." is not a valid identifier (ends with a dot).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
function x() -> a. {}
|
function x() -> a. {}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 3384: (22-24): "a." is not a valid identifier (ends with a dot).
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
let a. := 1
|
let a. := 1
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// SyntaxError 3384: (10-12): "a." is not a valid identifier (ends with a dot).
|
||||||
|
Loading…
Reference in New Issue
Block a user