mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Better error messages when writing to expressions that cannot be written to.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f(uint256 x) public pure returns (uint256, uint256) {
|
||||
uint256 b = x;
|
||||
x = 42;
|
||||
return (x, b);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f(uint256): 23 -> 42, 23
|
||||
@@ -0,0 +1,7 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
contract Test {
|
||||
function f(uint256[] calldata s) external { s[0] = 4; }
|
||||
}
|
||||
// ----
|
||||
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||
// TypeError: (98-102): Calldata arrays are read-only.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f (uint256[] calldata x) external pure {
|
||||
x.length = 42;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (75-83): Calldata arrays cannot be resized.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(uint256[] calldata x) external pure {
|
||||
x[0] = 42;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (74-78): Calldata arrays are read-only.
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
contract C {
|
||||
struct S { uint256 x; }
|
||||
function f(S calldata s) external pure {
|
||||
s.x = 42;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||
// TypeError: (128-131): Calldata structs are read-only.
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f(uint256[] calldata x, uint256[] calldata y) external pure {
|
||||
x = y;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (96-97): External function arguments of reference type are read-only.
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
function f() internal {
|
||||
}
|
||||
function g() internal {
|
||||
g = f;
|
||||
}
|
||||
function h() external {
|
||||
}
|
||||
function i() external {
|
||||
this.i = this.h;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (83-84): Expression has to be an lvalue.
|
||||
// TypeError: (166-172): Expression has to be an lvalue.
|
||||
@@ -0,0 +1,7 @@
|
||||
library L {
|
||||
function f(mapping(uint=>uint) storage x, mapping(uint=>uint) storage y) external {
|
||||
x = y;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (108-109): Mappings cannot be assigned to.
|
||||
@@ -0,0 +1,31 @@
|
||||
contract C {
|
||||
struct S { uint256 x; }
|
||||
function i() internal pure {}
|
||||
function e() external pure {}
|
||||
uint[] s1;
|
||||
function f(uint x, bytes32 y) external {
|
||||
x = 42;
|
||||
y = bytes32(0);
|
||||
(x, y) = (23, bytes32(0));
|
||||
S memory ms1;
|
||||
S memory ms2;
|
||||
ms1 = ms2;
|
||||
ms1.x = x;
|
||||
uint256[] memory a = new uint256[](2);
|
||||
uint256[] memory b = new uint256[](3);
|
||||
a = b;
|
||||
a[0] = x;
|
||||
s1[0] = x;
|
||||
s1 = a;
|
||||
}
|
||||
function g(function() internal pure x) internal view {
|
||||
x = i;
|
||||
function(uint, bytes32) external y;
|
||||
y = this.f;
|
||||
}
|
||||
function g(function() external pure x) external view {
|
||||
x = this.e;
|
||||
function(function() internal pure) internal view y;
|
||||
y = g;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
contract c {
|
||||
function f(uint a) external { a = 1; }
|
||||
function f(uint a) external pure { a = 1; }
|
||||
}
|
||||
// ----
|
||||
// TypeError: (47-48): Expression has to be an lvalue.
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
contract c {
|
||||
function f(uint a) external { a++; }
|
||||
function f(uint a) external pure { a++; }
|
||||
}
|
||||
// ----
|
||||
// TypeError: (47-48): Expression has to be an lvalue.
|
||||
|
||||
@@ -2,4 +2,4 @@ contract c {
|
||||
function f(uint a) external { delete a; }
|
||||
}
|
||||
// ----
|
||||
// TypeError: (54-55): Expression has to be an lvalue.
|
||||
// Warning: (17-58): Function state mutability can be restricted to pure
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (72-80): Expression has to be an lvalue.
|
||||
// TypeError: (72-80): Memory arrays cannot be resized.
|
||||
|
||||
@@ -7,4 +7,4 @@ contract Test {
|
||||
}
|
||||
// ----
|
||||
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||
// TypeError: (144-147): Expression has to be an lvalue.
|
||||
// TypeError: (144-147): Calldata structs are read-only.
|
||||
|
||||
@@ -5,4 +5,4 @@ contract Test {
|
||||
}
|
||||
// ----
|
||||
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||
// TypeError: (114-117): Expression has to be an lvalue.
|
||||
// TypeError: (114-117): Calldata structs are read-only.
|
||||
|
||||
@@ -6,7 +6,7 @@ contract Test {
|
||||
}
|
||||
// ----
|
||||
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||
// TypeError: (114-115): Expression has to be an lvalue.
|
||||
// TypeError: (114-115): External function arguments of reference type are read-only.
|
||||
// TypeError: (118-122): Type struct Test.S memory is not implicitly convertible to expected type struct Test.S calldata.
|
||||
// TypeError: (178-179): Expression has to be an lvalue.
|
||||
// TypeError: (178-179): External function arguments of reference type are read-only.
|
||||
// TypeError: (182-183): Type struct Test.S memory is not implicitly convertible to expected type struct Test.S calldata.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes32 x;
|
||||
x[0] = 0x42;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-75): Single bytes in fixed bytes arrays cannot be modified.
|
||||
Reference in New Issue
Block a user