mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4681 from ethereum/var-suggestion-crash
Fix declaration suggestion for var with different number of components
This commit is contained in:
commit
30f981fc2c
@ -1034,7 +1034,10 @@ string createTupleDecl(vector<ASTPointer<VariableDeclaration>> const& _decls)
|
||||
vector<string> components;
|
||||
for (ASTPointer<VariableDeclaration> const& decl: _decls)
|
||||
if (decl)
|
||||
{
|
||||
solAssert(decl->annotation().type, "");
|
||||
components.emplace_back(decl->annotation().type->toString(false) + " " + decl->name());
|
||||
}
|
||||
else
|
||||
components.emplace_back();
|
||||
|
||||
@ -1052,6 +1055,9 @@ bool typeCanBeExpressed(vector<ASTPointer<VariableDeclaration>> const& decls)
|
||||
if (!decl)
|
||||
continue;
|
||||
|
||||
if (!decl->annotation().type)
|
||||
return false;
|
||||
|
||||
if (auto functionType = dynamic_cast<FunctionType const*>(decl->annotation().type.get()))
|
||||
if (
|
||||
functionType->kind() != FunctionType::Kind::Internal &&
|
||||
|
@ -12,6 +12,10 @@ contract C {
|
||||
var myblockhash = block.blockhash;
|
||||
var (a, b) = (2, "troi");
|
||||
var (x,, z) = h();
|
||||
var (c, d) = ("");
|
||||
var (k, l) = (2);
|
||||
var (m, n) = 1;
|
||||
var (o, p) = "";
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@ -21,3 +25,11 @@ contract C {
|
||||
// SyntaxError: (293-326): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// SyntaxError: (336-360): Use of the "var" keyword is disallowed. Use explicit declaration `(uint8 a, string memory b) = ...´ instead.
|
||||
// SyntaxError: (370-387): Use of the "var" keyword is disallowed. Use explicit declaration `(uint256 x, , uint256 z) = ...´ instead.
|
||||
// TypeError: (397-414): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (397-414): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// TypeError: (424-440): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (424-440): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// TypeError: (450-464): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (450-464): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
// TypeError: (474-489): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// SyntaxError: (474-489): Use of the "var" keyword is disallowed. Type cannot be expressed in syntax.
|
||||
|
Loading…
Reference in New Issue
Block a user