Add InlineArrayType to support literals conversion to statically and dynamically allocated arrays.

This commit is contained in:
wechman
2022-08-29 07:18:35 +02:00
parent 7bfec3ba70
commit 1ef2f60049
63 changed files with 1581 additions and 384 deletions
@@ -4,4 +4,6 @@ contract C {
}
}
// ----
// TypeError 6378: (60-62): Unable to deduce common type for array elements.
// TypeError 8015: (60-62): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but inline_array() provided.
// TypeError 8015: (64-66): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but inline_array() provided.
// TypeError 8015: (68-70): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but inline_array() provided.
@@ -50,7 +50,7 @@ contract C {
// TypeError 8015: (796-797): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but function () provided.
// TypeError 8015: (811-813): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but tuple() provided.
// TypeError 8015: (827-833): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but tuple(int_const 0,int_const 0) provided.
// TypeError 8015: (847-850): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but uint8[1] memory provided.
// TypeError 8015: (847-850): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but inline_array(int_const 0) provided.
// TypeError 8015: (864-870): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but uint8[1] memory slice provided.
// TypeError 8015: (884-890): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but uint8 provided.
// TypeError 8015: (904-911): Invalid type for argument in the bytes.concat function call. bytes or fixed bytes type is required, but contract C provided.
@@ -11,7 +11,6 @@ contract C {
function () external returns(uint)[1] memory externalDefaultArray;
function () internal returns(uint)[1] memory internalDefaultArray;
// This would work if we were assigning to storage rather than memory
externalDefaultArray = [this.externalView];
internalDefaultArray = [internalView];
@@ -22,7 +21,6 @@ contract C {
function () external returns(uint)[1] memory externalDefaultArray;
function () internal returns(uint)[1] memory internalDefaultArray;
// This would work if we were assigning to storage rather than memory
externalDefaultArray = [this.externalPure];
internalDefaultArray = [internalPure];
@@ -33,7 +31,6 @@ contract C {
function () external returns(uint)[1] memory externalViewArray;
function () internal returns(uint)[1] memory internalViewArray;
// This would work if we were assigning to storage rather than memory
externalViewArray = [this.externalPure];
internalViewArray = [internalPure];
@@ -41,9 +38,7 @@ contract C {
}
}
// ----
// TypeError 7407: (760-779): Type function () view external returns (uint256)[1] memory is not implicitly convertible to expected type function () external returns (uint256)[1] memory.
// TypeError 7407: (812-826): Type function () view returns (uint256)[1] memory is not implicitly convertible to expected type function () returns (uint256)[1] memory.
// TypeError 7407: (1230-1249): Type function () pure external returns (uint256)[1] memory is not implicitly convertible to expected type function () external returns (uint256)[1] memory.
// TypeError 7407: (1282-1296): Type function () pure returns (uint256)[1] memory is not implicitly convertible to expected type function () returns (uint256)[1] memory.
// TypeError 7407: (1688-1707): Type function () pure external returns (uint256)[1] memory is not implicitly convertible to expected type function () external returns (uint256)[1] memory.
// TypeError 7407: (1737-1751): Type function () pure returns (uint256)[1] memory is not implicitly convertible to expected type function () returns (uint256)[1] memory.
// Warning 2018: (17-81): Function state mutability can be restricted to pure
// Warning 2018: (86-152): Function state mutability can be restricted to pure
// Warning 2018: (229-293): Function state mutability can be restricted to pure
// Warning 2018: (298-364): Function state mutability can be restricted to pure
@@ -1,4 +1,4 @@
pragma abicoder v2;
pragma abicoder v2;
contract C {
function f() public pure returns(string[5] calldata) {
@@ -6,4 +6,4 @@ contract C {
}
}
// ----
// TypeError 6359: (122-147): Return argument type string[5] memory is not implicitly convertible to expected type (type of first return variable) string[5] calldata.
// TypeError 6359: (108-133): Return argument type inline_array(literal_string "h", literal_string "e", literal_string "l", literal_string "l", literal_string "o") is not implicitly convertible to expected type (type of first return variable) string[5] calldata. Invalid conversion from literal_string "h" to string calldata.
@@ -0,0 +1,7 @@
contract C {
function f() public {
uint i = [0, 1, 2][];
}
}
// ----
// TypeError 5093: (56-67): Index expression cannot be omitted.
@@ -0,0 +1,8 @@
contract C {
function f() external pure {
bytes[2] memory a1 = ['foo', 'bar'];
bytes[2] memory a2 = [hex'666f6f', hex'626172'];
require(keccak256(a1[0]) == keccak256(a2[0]));
require(keccak256(a1[1]) == keccak256(a2[1]));
}
}
@@ -0,0 +1,13 @@
contract C {
function f(uint256[] memory x) private {}
function f(uint256[3] memory x) private {}
function g() private {
f([1]);
f([1,2,3]);
f([1,2,3,4]);
}
}
// ----
// TypeError 4487: (158-159): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,9 @@
contract C {
function f() external pure {
string[2] memory a1 = [string(bytes(hex'74000001')), string(bytes(hex'c0a80101'))];
bytes[2] memory a2 = [bytes(hex'74000001'), bytes(hex'c0a80101')];
}
}
// ----
// Warning 2072: (54-73): Unused local variable.
// Warning 2072: (146-164): Unused local variable.
@@ -0,0 +1,11 @@
contract C {
function f() external pure {
string[2] memory a1 = [hex'74000001', hex'c0a80101'];
string[2] memory a2 = [bytes(hex'74000001'), bytes(hex'c0a80101')];
bytes[2] memory a3 = [hex'74000001', hex'c0a80101'];
bytes[2] memory a4 = ['foo', 'bar'];
}
}
// ----
// TypeError 9574: (54-106): Type inline_array(literal_string hex"74000001", literal_string hex"c0a80101") is not implicitly convertible to expected type string[2] memory. Invalid conversion from literal_string hex"c0a80101" to string memory. Contains invalid UTF-8 sequence at position 4.
// TypeError 9574: (116-182): Type inline_array(bytes memory, bytes memory) is not implicitly convertible to expected type string[2] memory. Invalid conversion from bytes memory to string memory.
@@ -0,0 +1,7 @@
contract C {
function f() public {
uint[3] memory x = [1, 2];
}
}
// ----
// TypeError 9574: (47-72): Type inline_array(int_const 1, int_const 2) is not implicitly convertible to expected type uint256[3] memory. Number of components in array literal (2) does not match array size (3).
@@ -4,4 +4,4 @@ contract C {
}
}
// ----
// TypeError 6378: (66-83): Unable to deduce common type for array elements.
// TypeError 9574: (47-83): Type inline_array(int_const 45, literal_string "foo", bool) is not implicitly convertible to expected type uint256[3] memory. Invalid conversion from literal_string "foo" to uint256.
@@ -24,4 +24,4 @@ contract C {
// TypeError 7788: (382-408): Expected 1 instead of 0 components for the tuple parameter.
// TypeError 6219: (489-511): Expected two arguments: a function pointer followed by a tuple.
// TypeError 7515: (597-628): Expected a tuple with 2 components instead of a single non-tuple parameter.
// TypeError 5407: (621-627): Cannot implicitly convert component at position 0 from "uint8[2] memory" to "int256".
// TypeError 5407: (621-627): Cannot implicitly convert component at position 0 from "inline_array(int_const 1, int_const 2)" to "int256": Array literal can not be converted to byte array or string.
@@ -4,4 +4,6 @@ contract C {
}
}
// ----
// TypeError 6378: (61-63): Unable to deduce common type for array elements.
// TypeError 9977: (61-63): Invalid type for argument in the string.concat function call. string type is required, but t_inline_array$__$ provided.
// TypeError 9977: (65-67): Invalid type for argument in the string.concat function call. string type is required, but t_inline_array$__$ provided.
// TypeError 9977: (69-71): Invalid type for argument in the string.concat function call. string type is required, but t_inline_array$__$ provided.
@@ -50,7 +50,7 @@ contract C {
// TypeError 9977: (797-798): Invalid type for argument in the string.concat function call. string type is required, but t_function_internal_nonpayable$__$returns$__$ provided.
// TypeError 9977: (812-814): Invalid type for argument in the string.concat function call. string type is required, but t_tuple$__$ provided.
// TypeError 9977: (828-834): Invalid type for argument in the string.concat function call. string type is required, but t_tuple$_t_rational_0_by_1_$_t_rational_0_by_1_$ provided.
// TypeError 9977: (848-851): Invalid type for argument in the string.concat function call. string type is required, but t_array$_t_uint8_$1_memory_ptr provided.
// TypeError 9977: (848-851): Invalid type for argument in the string.concat function call. string type is required, but t_inline_array$_t_rational_0_by_1_$ provided.
// TypeError 9977: (865-871): Invalid type for argument in the string.concat function call. string type is required, but t_array$_t_uint8_$1_memory_ptr_slice provided.
// TypeError 9977: (885-891): Invalid type for argument in the string.concat function call. string type is required, but t_uint8 provided.
// TypeError 9977: (905-912): Invalid type for argument in the string.concat function call. string type is required, but t_contract$_C_$61 provided.