mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Update tests.
This commit is contained in:
parent
6f383e1626
commit
62645d5302
@ -8091,17 +8091,36 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
|
||||
function g() public returns (uint a, uint b, uint c) {
|
||||
a = 1; b = 2; c = 3;
|
||||
}
|
||||
function f() public returns (bool) {
|
||||
function h() public returns (uint a, uint b, uint c, uint d) {
|
||||
a = 1; b = 2; c = 3; d = 4;
|
||||
}
|
||||
function f1() public returns (bool) {
|
||||
(uint x, uint y, uint z) = g();
|
||||
if (x != 1 || y != 2 || z != 3) return false;
|
||||
(, uint a,) = g();
|
||||
if (a != 2) return false;
|
||||
(uint b,) = g();
|
||||
(uint b, , ) = g();
|
||||
if (b != 1) return false;
|
||||
(, uint c) = g();
|
||||
(, , uint c) = g();
|
||||
if (c != 3) return false;
|
||||
return true;
|
||||
}
|
||||
function f2() public returns (bool) {
|
||||
(uint a1, , uint a3, ) = h();
|
||||
if (a1 != 1 || a3 != 3) return false;
|
||||
(uint b1, uint b2, , ) = h();
|
||||
if (b1 != 1 || b2 != 2) return false;
|
||||
(, uint c2, uint c3, ) = h();
|
||||
if (c2 != 2 || c3 != 3) return false;
|
||||
(, , uint d3, uint d4) = h();
|
||||
if (d3 != 3 || d4 != 4) return false;
|
||||
(uint e1, , uint e3, uint e4) = h();
|
||||
if (e1 != 1 || e3 != 3 || e4 != 4) return false;
|
||||
return true;
|
||||
}
|
||||
function f() public returns (bool) {
|
||||
return f1() && f2();
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
|
@ -0,0 +1,25 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
uint a = (1,2);
|
||||
uint b = (1,2,3);
|
||||
uint c = (1,2,3,4);
|
||||
}
|
||||
function g() public {
|
||||
(uint a1, uint b1, uint c1, uint d1) = 1;
|
||||
(uint a2, uint b2, uint c2) = 1;
|
||||
(uint a3, uint b3) = 1;
|
||||
}
|
||||
function h() public {
|
||||
(uint a1, uint b1, uint c1, uint d1) = (1,2,3);
|
||||
(uint a2, uint b2, uint c2) = (1,2,3,4);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (47-61): Different number of components on the left hand side (1) than on the right hand side (2).
|
||||
// TypeError: (71-87): Different number of components on the left hand side (1) than on the right hand side (3).
|
||||
// TypeError: (97-115): Different number of components on the left hand side (1) than on the right hand side (4).
|
||||
// TypeError: (157-197): Different number of components on the left hand side (4) than on the right hand side (1).
|
||||
// TypeError: (207-238): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (248-270): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// TypeError: (312-358): Different number of components on the left hand side (4) than on the right hand side (3).
|
||||
// TypeError: (368-407): Different number of components on the left hand side (3) than on the right hand side (4).
|
@ -0,0 +1,29 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
uint a = two();
|
||||
uint b = three();
|
||||
uint c = four();
|
||||
}
|
||||
function g() public {
|
||||
(uint a1, uint b1, uint c1, uint d1) = one();
|
||||
(uint a2, uint b2, uint c2) = one();
|
||||
(uint a3, uint b3) = one();
|
||||
}
|
||||
function h() public {
|
||||
(uint a1, uint b1, uint c1, uint d1) = three();
|
||||
(uint a2, uint b2, uint c2) = four();
|
||||
}
|
||||
function one() public pure returns (uint);
|
||||
function two() public pure returns (uint, uint);
|
||||
function three() public pure returns (uint, uint, uint);
|
||||
function four() public pure returns (uint, uint, uint, uint);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (47-61): Different number of components on the left hand side (1) than on the right hand side (2).
|
||||
// TypeError: (71-87): Different number of components on the left hand side (1) than on the right hand side (3).
|
||||
// TypeError: (97-112): Different number of components on the left hand side (1) than on the right hand side (4).
|
||||
// TypeError: (154-198): Different number of components on the left hand side (4) than on the right hand side (1).
|
||||
// TypeError: (208-243): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (253-279): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// TypeError: (321-367): Different number of components on the left hand side (4) than on the right hand side (3).
|
||||
// TypeError: (377-413): Different number of components on the left hand side (3) than on the right hand side (4).
|
@ -0,0 +1,24 @@
|
||||
contract C {
|
||||
function fn() public pure {
|
||||
(uint a,) = (1,2,3);
|
||||
(,uint b) = (1,2,3);
|
||||
(,uint c,) = (1,2,3,4,5);
|
||||
(uint d, uint e,) = (1,2,3,4);
|
||||
(,uint f, uint g) = (1,2,3,4);
|
||||
(,uint h, uint i,) = (1,2,3);
|
||||
(uint j,) = 1;
|
||||
(,uint k) = 1;
|
||||
(,uint l,) = 1;
|
||||
a;b;c;d;e;f;g;h;i;j;k;l;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (53-72): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// TypeError: (82-101): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// TypeError: (111-135): Different number of components on the left hand side (3) than on the right hand side (5).
|
||||
// TypeError: (145-174): Different number of components on the left hand side (3) than on the right hand side (4).
|
||||
// TypeError: (184-213): Different number of components on the left hand side (3) than on the right hand side (4).
|
||||
// TypeError: (223-251): Different number of components on the left hand side (4) than on the right hand side (3).
|
||||
// TypeError: (261-274): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// TypeError: (284-297): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// TypeError: (307-321): Different number of components on the left hand side (3) than on the right hand side (1).
|
@ -0,0 +1,31 @@
|
||||
contract C {
|
||||
function fn() public pure {
|
||||
(uint a,) = three();
|
||||
(,uint b) = three();
|
||||
(,uint c,) = five();
|
||||
(uint d, uint e,) = four();
|
||||
(,uint f, uint g) = four();
|
||||
(,uint h, uint i,) = three();
|
||||
(uint j,) = one();
|
||||
(,uint k) = one();
|
||||
(,uint l,) = one();
|
||||
(,uint m, uint n,) = five();
|
||||
a;b;c;d;e;f;g;h;i;j;k;l;m;n;
|
||||
}
|
||||
function one() public pure returns (uint);
|
||||
function two() public pure returns (uint, uint);
|
||||
function three() public pure returns (uint, uint, uint);
|
||||
function four() public pure returns (uint, uint, uint, uint);
|
||||
function five() public pure returns (uint, uint, uint, uint, uint);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (53-72): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// TypeError: (82-101): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// TypeError: (111-130): Different number of components on the left hand side (3) than on the right hand side (5).
|
||||
// TypeError: (140-166): Different number of components on the left hand side (3) than on the right hand side (4).
|
||||
// TypeError: (176-202): Different number of components on the left hand side (3) than on the right hand side (4).
|
||||
// TypeError: (212-240): Different number of components on the left hand side (4) than on the right hand side (3).
|
||||
// TypeError: (250-267): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// TypeError: (277-294): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// TypeError: (304-322): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (332-359): Different number of components on the left hand side (4) than on the right hand side (5).
|
@ -2,10 +2,10 @@ contract D {
|
||||
struct S { uint a; uint b; }
|
||||
}
|
||||
contract C {
|
||||
function f() internal returns (uint, uint, uint, D.S[20] storage, uint) {
|
||||
(,,,D.S[10*2] storage x,) = f();
|
||||
function f() internal pure {
|
||||
(,,,D.S[10*2] storage x,) = g();
|
||||
x;
|
||||
}
|
||||
}
|
||||
function g() internal pure returns (uint, uint, uint, D.S[20] storage x, uint) { x = x; }
|
||||
}
|
||||
// ----
|
||||
// Warning: (110-117): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
|
@ -0,0 +1,11 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
(uint a, uint b) = f();
|
||||
(uint c) = f();
|
||||
uint d = f();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (52-74): Different number of components on the left hand side (2) than on the right hand side (0).
|
||||
// TypeError: (84-98): Different number of components on the left hand side (1) than on the right hand side (0).
|
||||
// TypeError: (108-120): Different number of components on the left hand side (1) than on the right hand side (0).
|
@ -1,12 +1,12 @@
|
||||
contract C {
|
||||
function f() internal returns (uint, uint, uint, uint) {
|
||||
function f() internal pure returns (uint, uint, uint, uint) {
|
||||
(uint a, uint b,,) = f();
|
||||
a; b;
|
||||
}
|
||||
function g() internal returns (bytes memory, string storage) {
|
||||
(bytes memory a, string storage b) = g();
|
||||
function g() internal pure {
|
||||
(bytes memory a, string storage b) = h();
|
||||
a; b;
|
||||
}
|
||||
}
|
||||
function h() internal pure returns (bytes memory, string storage s) { s = s; }
|
||||
}
|
||||
// ----
|
||||
// Warning: (163-169): This variable is of storage pointer type and might be returned without assignment. This can cause storage corruption. Assign the variable (potentially from itself) to remove this warning.
|
||||
|
@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
(uint a,) = (1,);
|
||||
a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (59-63): Tuple component cannot be empty.
|
@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
(uint a1, uint b1, uint c1, uint d1) = (1,2,3,4);
|
||||
(uint a2, uint b2, uint c2) = (1,2,3);
|
||||
(uint a3, uint b3) = (1,2);
|
||||
a1; b1; c1; d1; a2; b2; c2; a3; b3;
|
||||
}
|
||||
}
|
||||
// ----
|
@ -1,21 +0,0 @@
|
||||
contract C {
|
||||
function three() public returns (uint, uint, uint);
|
||||
function two() public returns (uint, uint);
|
||||
function none() public;
|
||||
function f() public {
|
||||
(uint a,) = three();
|
||||
(uint b, uint c,) = two();
|
||||
(,uint d) = three();
|
||||
(,uint e, uint g) = two();
|
||||
var (,,) = three();
|
||||
var () = none();
|
||||
a;b;c;d;e;g;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// SyntaxError: (307-325): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
|
||||
// SyntaxError: (335-350): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
|
||||
// Warning: (179-198): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// Warning: (208-233): Different number of components on the left hand side (3) than on the right hand side (2).
|
||||
// Warning: (243-262): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// Warning: (272-297): Different number of components on the left hand side (3) than on the right hand side (2).
|
@ -1,7 +0,0 @@
|
||||
contract C {
|
||||
function one() public returns (uint);
|
||||
function f() public { (uint a, uint b, ) = one(); }
|
||||
}
|
||||
// ----
|
||||
// Warning: (81-107): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (81-107): Not enough components (1) in value to assign all variables (2).
|
@ -1,7 +0,0 @@
|
||||
contract C {
|
||||
function one() public returns (uint);
|
||||
function f() public { (uint a, , ) = one(); }
|
||||
}
|
||||
// ----
|
||||
// Warning: (81-101): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (81-101): Not enough components (1) in value to assign all variables (2).
|
@ -1,7 +0,0 @@
|
||||
contract C {
|
||||
function one() public returns (uint);
|
||||
function f() public { (, , uint a) = one(); }
|
||||
}
|
||||
// ----
|
||||
// Warning: (81-101): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (81-101): Not enough components (1) in value to assign all variables (2).
|
@ -1,7 +0,0 @@
|
||||
contract C {
|
||||
function one() public returns (uint);
|
||||
function f() public { (, uint a, uint b) = one(); }
|
||||
}
|
||||
// ----
|
||||
// Warning: (81-107): Different number of components on the left hand side (3) than on the right hand side (1).
|
||||
// TypeError: (81-107): Not enough components (1) in value to assign all variables (2).
|
@ -1,13 +1,10 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
function f() public pure {
|
||||
uint a = (1);
|
||||
(uint b,) = uint8(1);
|
||||
(uint b,) = (uint8(1),2);
|
||||
(uint c, uint d) = (uint32(1), 2 + a);
|
||||
(uint e,) = (uint64(1), 2, b);
|
||||
(uint e, ,) = (uint64(1), 2, b);
|
||||
a;b;c;d;e;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (69-89): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// Warning: (146-175): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// Warning: (17-201): Function state mutability can be restricted to pure
|
||||
|
@ -1,7 +0,0 @@
|
||||
contract C {
|
||||
function one() public returns (uint);
|
||||
function f() public { var (,) = one(); }
|
||||
}
|
||||
// ----
|
||||
// SyntaxError: (81-96): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
|
||||
// TypeError: (81-96): Wildcard both at beginning and end of variable declaration list is only allowed if the number of components is equal.
|
@ -1,7 +0,0 @@
|
||||
contract C {
|
||||
function two() public returns (uint, uint);
|
||||
function f() public { (uint a, uint b, uint c) = two(); }
|
||||
}
|
||||
// ----
|
||||
// Warning: (87-119): Different number of components on the left hand side (3) than on the right hand side (2).
|
||||
// TypeError: (87-119): Not enough components (2) in value to assign all variables (3).
|
@ -2,8 +2,8 @@ contract C {
|
||||
function f() pure public {
|
||||
(uint a, uint b, uint c) = g();
|
||||
(uint d) = 2;
|
||||
(, uint e) = 3;
|
||||
(uint h,) = 4;
|
||||
(, uint e) = (3,4);
|
||||
(uint h,) = (4,5);
|
||||
(uint x,,) = g();
|
||||
(, uint y,) = g();
|
||||
a; b; c; d; e; h; x; y;
|
||||
@ -11,5 +11,3 @@ contract C {
|
||||
function g() pure public returns (uint, uint, uint) {}
|
||||
}
|
||||
// ----
|
||||
// Warning: (93-107): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// Warning: (111-124): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
|
@ -1,16 +1,11 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
function f() public pure {
|
||||
uint a = (1);
|
||||
(uint b,) = 1;
|
||||
(uint b,) = (1,2);
|
||||
(uint c, uint d) = (1, 2 + a);
|
||||
(uint e,) = (1, 2, b);
|
||||
(uint e,) = (1, b);
|
||||
(a) = 3;
|
||||
a;b;c;d;e;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (54-67): Different number of components on the left hand side (2) than on the right hand side (1).
|
||||
// Warning: (104-125): Different number of components on the left hand side (2) than on the right hand side (3).
|
||||
// Warning: (72-78): Unused local variable.
|
||||
// Warning: (80-86): Unused local variable.
|
||||
// Warning: (105-111): Unused local variable.
|
||||
// Warning: (14-140): Function state mutability can be restricted to pure
|
||||
|
@ -1,8 +0,0 @@
|
||||
contract C {
|
||||
function f() public pure returns (uint, uint, uint, uint) {
|
||||
(uint a, uint b,) = f();
|
||||
a; b;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (76-99): Different number of components on the left hand side (3) than on the right hand side (4).
|
@ -16,4 +16,3 @@ contract C {
|
||||
// SyntaxError: (249-261): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
|
||||
// SyntaxError: (271-283): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
|
||||
// SyntaxError: (293-306): The use of the "var" keyword is disallowed. The declaration part of the statement can be removed, since it is empty.
|
||||
// TypeError: (271-283): Too many components (1) in value for variable assignment (0) needed
|
||||
|
Loading…
Reference in New Issue
Block a user