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
@@ -30,6 +30,6 @@ contract C is B {
}
// ----
// test() -> 77
// gas irOptimized: 120170
// gas legacy: 155093
// gas legacyOptimized: 111550
// gas irOptimized: 115552
// gas legacy: 159144
// gas legacyOptimized: 110758
@@ -13,8 +13,8 @@ contract Test {
// ----
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
// gas irOptimized: 186766
// gas legacy: 211149
// gas legacyOptimized: 206054
// gas legacy: 211155
// gas legacyOptimized: 206060
// data(uint256,uint256): 0x02, 0x02 -> 0x09
// data(uint256,uint256): 0x05, 0x01 -> 0x11
// data(uint256,uint256): 0x06, 0x00 -> FAILURE
@@ -21,6 +21,6 @@ contract c {
// ----
// store(uint256[9],uint8[3][]): 21, 22, 23, 24, 25, 26, 27, 28, 29, 0x140, 4, 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33 -> 32
// gas irOptimized: 648324
// gas legacy: 694515
// gas legacyOptimized: 694013
// gas legacy: 694519
// gas legacyOptimized: 694017
// retrieve() -> 9, 28, 9, 28, 4, 3, 32
@@ -47,5 +47,5 @@ contract C {
// ----
// f() -> true
// gas irOptimized: 146936
// gas legacy: 155961
// gas legacyOptimized: 153588
// gas legacy: 155962
// gas legacyOptimized: 153589
@@ -20,5 +20,5 @@ contract c {
// ----
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x05000000000000000000000000000000000000000000000000
// gas irOptimized: 208149
// gas legacy: 221856
// gas legacyOptimized: 220680
// gas legacy: 221858
// gas legacyOptimized: 220682
@@ -24,5 +24,5 @@ contract c {
// ----
// test() -> 3, 4
// gas irOptimized: 189690
// gas legacy: 195353
// gas legacyOptimized: 192441
// gas legacy: 195355
// gas legacyOptimized: 192443
@@ -21,4 +21,4 @@ contract c {
// test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000
// gas irOptimized: 124910
// gas legacy: 187414
// gas legacyOptimized: 165659
// gas legacyOptimized: 165660
@@ -11,8 +11,8 @@ contract Test {
// ----
// set(uint24[]): 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 -> 18
// gas irOptimized: 99616
// gas legacy: 103563
// gas legacyOptimized: 101397
// gas legacy: 103564
// gas legacyOptimized: 101398
// data(uint256): 7 -> 8
// data(uint256): 15 -> 16
// data(uint256): 18 -> FAILURE
@@ -16,7 +16,7 @@ contract C {
}
// ----
// constructor()
// gas irOptimized: 237351
// gas legacy: 221315
// gas legacyOptimized: 185247
// gas irOptimized: 192200
// gas legacy: 237108
// gas legacyOptimized: 190689
// f() -> 0
@@ -17,5 +17,5 @@ contract C {
// ----
// test() -> 7
// gas irOptimized: 122483
// gas legacy: 205196
// gas legacyOptimized: 204987
// gas legacy: 205197
// gas legacyOptimized: 204988
@@ -21,6 +21,6 @@ contract C {
// compileToEwasm: also
// ----
// one() -> 3
// gas legacy: 140260
// gas legacyOptimized: 140097
// gas legacy: 140261
// gas legacyOptimized: 140098
// two() -> FAILURE, hex"4e487b71", 0x51
@@ -0,0 +1,18 @@
contract C {
function f() public returns (uint8[3] memory) {
uint8[3][] memory x = new uint8[3][](1);
x[0] = [1, 2, 3];
return x[0];
}
function g() public returns (uint8[] memory) {
uint8[][] memory x = new uint8[][](1);
x[0] = [4, 5, 6];
return x[0];
}
}
// ====
// compileViaYul: also
// ----
// f() -> 1, 2, 3
// g() -> 0x20, 3, 4, 5, 6
@@ -0,0 +1,25 @@
contract C {
uint8[3][] x;
uint8[][] y;
constructor() {
x = new uint8[3][](1);
x[0] = [1, 2, 3];
y = new uint8[][](1);
y[0] = [4, 5, 6];
}
function f() public returns (uint8[3] memory) {
return x[0];
}
function g() public returns (uint8[] memory) {
return y[0];
}
}
// ====
// compileViaYul: also
// ----
// f() -> 1, 2, 3
// g() -> 0x20, 3, 4, 5, 6
@@ -0,0 +1,15 @@
pragma abicoder v2;
contract C {
string sString = "text2";
function f(string calldata cString) public returns (string[] memory) {
string memory mString = "text3";
return ["", "text1", sString, mString, cString];
}
}
// ====
// compileViaYul: true
// ----
// f(string): 0x20, 5, "text4" -> 0x20, 5, 0xa0, 0xc0, 0x0100, 0x0140, 0x0180, 0, 5, 52647573331277248417481526129911949709942841133814091230869433742303074189312, 5, 52647573331382560709150083316609867737626511566132986326269982853557385166848, 5, 52647573331487873000818640503307785765310181998451881421670531964811696144384, 5, 52647573331593185292487197690005703792993852430770776517071081076066007121920
@@ -0,0 +1,27 @@
pragma abicoder v2;
contract C {
function f() public returns (uint8[] memory) {
return [1, 2, 3, 4, 5];
}
function g() public returns (uint8[][] memory) {
return [[1, 2], [3], []];
}
function h() public returns (uint8[][3] memory) {
return [[1, 2], [3], []];
}
function i() public returns (uint8[2][] memory) {
return [[1, 2], [3,4], [5,6]];
}
}
// ====
// compileViaYul: true
// ----
// f() -> 0x20, 5, 1, 2, 3, 4, 5
// g() -> 0x20, 3, 0x60, 0xc0, 0x0100, 2, 1, 2, 1, 3, 0
// h() -> 0x20, 0x60, 0xc0, 0x0100, 2, 1, 2, 1, 3, 0
// i() -> 0x20, 3, 1, 2, 3, 4, 5, 6
@@ -0,0 +1,63 @@
pragma abicoder v2;
contract C {
struct CustomStruct{
uint16 index;
string text;
}
function statically_sized_uint_array() public returns (uint8[3] memory) {
uint8[3] memory a = [1, 2, 3];
return a;
}
function dynamically_sized_uint_array() public returns (uint8[] memory) {
uint8[] memory a = [1, 2, 3];
return a;
}
function statically_sized_int_array() public returns (int8[3] memory) {
int8[3] memory a = [-1, -2, -3];
return a;
}
function dynamically_sized_int_array() public returns (int8[] memory) {
int8[] memory a = [-1, -2, -3];
return a;
}
function statically_sized_string_array() public returns (string[2] memory) {
string[2] memory a = ["foo", "bar"];
return a;
}
function dynamically_sized_string_array() public returns (string[] memory) {
string[] memory a = ["foo", "bar"];
return a;
}
function statically_sized_struct_array() public returns (CustomStruct[2] memory) {
CustomStruct[2] memory s = [CustomStruct(1, "foo"), CustomStruct(2, "bar")];
return s;
}
function dynamically_sized_struct_array() public returns (CustomStruct[] memory) {
CustomStruct[] memory s = [CustomStruct(1, "foo"), CustomStruct(2, "bar")];
return s;
}
}
// ====
// EVMVersion: >=constantinople
// compileToEwasm: also
// compileViaYul: also
// ----
// statically_sized_uint_array() -> 1, 2, 3
// dynamically_sized_uint_array() -> 0x20, 3, 1, 2, 3
// statically_sized_int_array() -> -1, -2, -3
// dynamically_sized_int_array() -> 0x20, 3, -1, -2, -3
// statically_sized_string_array() -> 0x20, 0x40, 0x80, 3, "foo", 3, "bar"
// dynamically_sized_string_array() -> 0x20, 2, 0x40, 0x80, 3, 46332796673528066027243215619882264990369332300865266851730502456685210107904, 3, 44498830125527143464827115118378702402016761369235290884359940707316142178304
// statically_sized_struct_array() -> 0x20, 0x40, 0xc0, 1, 0x40, 3, 46332796673528066027243215619882264990369332300865266851730502456685210107904, 2, 0x40, 3, 44498830125527143464827115118378702402016761369235290884359940707316142178304
// dynamically_sized_struct_array() -> 0x20, 2, 0x40, 0xc0, 1, 0x40, 3, 46332796673528066027243215619882264990369332300865266851730502456685210107904, 2, 0x40, 3, 44498830125527143464827115118378702402016761369235290884359940707316142178304
@@ -0,0 +1,20 @@
contract C {
uint8[3] st = [1, 2, 3];
uint8[] public dt = [4, 5, 6];
function s() public returns (uint8[3] memory) {
return st;
}
function d() public returns (uint8[] memory) {
return dt;
}
}
// ====
// EVMVersion: >=constantinople
// compileToEwasm: also
// compileViaYul: also
// ----
// s() -> 1, 2, 3
// d() -> 0x20, 3, 4, 5, 6
@@ -0,0 +1,20 @@
pragma abicoder v2;
contract C {
uint8[3][2] st = [[1, 2, 3], [4, 5, 6]];
uint8[][] dt = [[1, 2], [3, 4, 5, 6]];
function s() public returns (uint8[3][2] memory) {
return st;
}
function d() public returns (uint8[][] memory) {
return dt;
}
}
// ====
// compileViaYul: true
// ----
// s() -> 1, 2, 3, 4, 5, 6
// d() -> 0x20, 2, 0x40, 0xa0, 2, 1, 2, 4, 3, 4, 5, 6
@@ -0,0 +1,11 @@
pragma abicoder v2;
contract C {
function f() external pure returns (string[2] memory rdatas) {
rdatas = [hex'74000001', hex'c4a40001'];
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0x20, 0x40, 0x80, 4, "t\0\0\x01", 4, "\xc4\xa4\0\x01"
@@ -0,0 +1,12 @@
contract C {
bytes[2] public staticBytesArray = [hex"616263", hex"646566"];
bytes[] public dynamicBytesArray = [hex"616263", hex"646566"];
}
// ====
// compileViaYul: also
// ----
// staticBytesArray(uint256): 0 -> 0x20, 3, 0x6162630000000000000000000000000000000000000000000000000000000000
// staticBytesArray(uint256): 1 -> 0x20, 3, 0x6465660000000000000000000000000000000000000000000000000000000000
// dynamicBytesArray(uint256): 0 -> 0x20, 3, 0x6162630000000000000000000000000000000000000000000000000000000000
// dynamicBytesArray(uint256): 1 -> 0x20, 3, 0x6465660000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,16 @@
contract C {
string[4] public staticArray = ["foo", "", "a very long string that needs more than 32 bytes", "bar"];
string[] public dynamicArray = ["foo", "", "a very long string that needs more than 32 bytes", "bar"];
}
// ====
// compileViaYul: also
// ----
// staticArray(uint256): 0 -> 0x20, 3, "foo"
// staticArray(uint256): 1 -> 0x20, 0
// staticArray(uint256): 2 -> 0x20, 0x30, 0x612076657279206c6f6e6720737472696e672074686174206e65656473206d6f, 0x7265207468616E20333220627974657300000000000000000000000000000000
// staticArray(uint256): 3 -> 0x20, 3, "bar"
// dynamicArray(uint256): 0 -> 0x20, 3, "foo"
// dynamicArray(uint256): 1 -> 0x20, 0
// dynamicArray(uint256): 2 -> 0x20, 0x30, 0x612076657279206c6f6e6720737472696e672074686174206e65656473206d6f, 0x7265207468616E20333220627974657300000000000000000000000000000000
// dynamicArray(uint256): 3 -> 0x20, 3, "bar"
@@ -0,0 +1,39 @@
pragma abicoder v2;
contract C {
function test1() public returns (uint8[1][] memory) {
uint8[1][] memory a = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16]];
return a;
}
function test2() public returns (int8[2][] memory) {
int8[2][] memory a = [[-1, -2], [-3, -4], [-5, -6]];
return a;
}
function test3() public returns (uint16[][2] memory) {
uint16[][2] memory a = [[1, 2, 3],[4, 5, 6, 7, 8, 9, 10, 11, 12, 13]];
return a;
}
function test4() public returns (uint8[][2][] memory) {
uint8[][2][] memory a = [[[1, 2, 3], [4, 5]], [[6], [7]], [[8, 9, 10, 11], [12, 13, 14, 15, 16]]];
return a;
}
function test5() public returns (string[2][] memory) {
string[2][] memory a = [["this", "is"], ["just", "a"], ["test", "array"]];
return a;
}
}
// ====
// compileViaYul: also
// ----
// test1() -> 0x20, 0x10, 0x01, 0x02, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0x10
// test2() -> 0x20, 0x03, -1, -2, -3, -4, -5, -6
// test3() -> 0x20, 0x40, 0xc0, 0x03, 1, 2, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
// test4() -> 0x20, 0x03, 0x60, 0x0180, 0x0240, 0x40, 0xc0, 3, 1, 2, 3, 2, 4, 5, 0x40, 0x80, 1, 6, 1, 7, 0x40, 0xe0, 4, 8, 9, 10, 11, 5, 12, 13, 14, 15, 0x10
// test5() -> 0x20, 3, 0x60, 288, 0x01e0, 0x40, 0x80, 4, 52652770314156132753103522558211245866589054961607131434777992190478746910720, 2, 47696036513692484977101116032555085334762927796157333774492759403894270853120, 0x40, 0x80, 4, 48152679884589002438443377966044670264050608660991796074848385302132292583424, 1, 43874346312576839672212443538448152585028080127215369968075725190498334277632, 0x40, 0x80, 4, 52647538817385212172903286807934654968315727694643370704309751478220717293568, 5, 44076556304902723615564186688849689667362290371271333483270849954029028507648
@@ -0,0 +1,38 @@
pragma abicoder v2;
contract C {
uint8[1][] array1 = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16]];
int8[2][] array2 = [[1, 2], [3, 4], [5, 6]];
uint16[][2] array3 = [[1, 2, 3],[4, 5, 6, 7, 8, 9, 10, 11, 12, 13]];
uint8[][2][] array4 = [[[1, 2, 3], [4, 5]], [[6], [7]], [[8, 9, 10, 11], [12, 13, 14, 15, 16]]];
string[2][] array5 = [["this", "is"], ["just", "a"], ["test", "array"]];
function test1() public returns (uint8[1][] memory) {
return array1;
}
function test2() public returns (int8[2][] memory) {
return array2;
}
function test3() public returns (uint16[][2] memory) {
return array3;
}
function test4() public returns (uint8[][2][] memory) {
return array4;
}
function test5() public returns (string[2][] memory) {
return array5;
}
}
// ====
// compileViaYul: also
// ----
// test1() -> 0x20, 0x10, 0x01, 0x02, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0x10
// test2() -> 0x20, 0x03, 0x01, 0x02, 3, 4, 5, 6
// test3() -> 0x20, 0x40, 0xc0, 0x03, 1, 2, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
// test4() -> 0x20, 0x03, 0x60, 0x0180, 0x0240, 0x40, 0xc0, 3, 1, 2, 3, 2, 4, 5, 0x40, 0x80, 1, 6, 1, 7, 0x40, 0xe0, 4, 8, 9, 10, 11, 5, 12, 13, 14, 15, 0x10
// test5() -> 0x20, 3, 0x60, 288, 0x01e0, 0x40, 0x80, 4, 52652770314156132753103522558211245866589054961607131434777992190478746910720, 2, 47696036513692484977101116032555085334762927796157333774492759403894270853120, 0x40, 0x80, 4, 48152679884589002438443377966044670264050608660991796074848385302132292583424, 1, 43874346312576839672212443538448152585028080127215369968075725190498334277632, 0x40, 0x80, 4, 52647538817385212172903286807934654968315727694643370704309751478220717293568, 5, 44076556304902723615564186688849689667362290371271333483270849954029028507648
@@ -0,0 +1,29 @@
pragma abicoder v2;
contract C {
uint8[] array1 = [1,2,3,4,5,6,7,8,9,10,11,12,13, 14, 15, 16];
uint8[][] array2 = [[1, 2, 3],[4, 5],[6,7,8,9,10,11,12], [13,14,15,16]];
uint8[][][] array3 = [[[1, 2, 3],[4, 5],[6]], [[7, 8, 9, 10,11],[12, 13,14,15,16]]];
function test1() public returns (uint8[] memory) {
return array1;
}
function test2() public returns (uint8[][] memory) {
return array2;
}
function test3() public returns (uint8[][][] memory) {
return array3;
}
}
// ====
// EVMVersion: >=constantinople
// compileToEwasm: also
// compileViaYul: also
// ----
// test1() -> 0x20, 0x10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0x10
// test2() -> 0x20, 4, 0x80, 0x0100, 0x0160, 0x0260, 3, 1, 2, 3, 2, 4, 5, 7, 6, 7, 8, 9, 10, 11, 12, 4, 13, 14, 15, 0x10
// test3() -> 0x20, 0x02, 0x40, 0x01e0, 0x03, 0x60, 0xe0, 0x0140, 3, 1, 2, 3, 2, 4, 5, 1, 6, 2, 0x40, 0x0100, 5, 7, 8, 9, 10, 11, 5, 12, 13, 14, 15, 0x10
@@ -0,0 +1,25 @@
contract C {
uint16[1][16] array1 = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16]];
uint16[4][2] array2 = [[1, 2, 3, 4], [5, 6, 7, 8]];
uint8[4][2][2] array3 = [[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]];
function test1() public returns (uint16[1][16] memory) {
return array1;
}
function test2() public returns (uint16[4][2] memory) {
return array2;
}
function test3() public returns (uint8[4][2][2] memory) {
return array3;
}
}
// ====
// compileToEwasm: also
// compileViaYul: also
// ----
// test1() -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
// test2() -> 1, 2, 3, 4, 5, 6, 7, 8
// test3() -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
@@ -13,5 +13,5 @@ contract C {
// ----
// f(uint120[]): 0x20, 3, 1, 2, 3 -> 1
// gas irOptimized: 112832
// gas legacy: 113686
// gas legacyOptimized: 113499
// gas legacy: 113687
// gas legacyOptimized: 113500
@@ -21,5 +21,5 @@ contract c {
// ----
// test() -> 2, 3, 4, 5
// gas irOptimized: 135204
// gas legacy: 147484
// gas legacyOptimized: 146456
// gas legacy: 147486
// gas legacyOptimized: 146458
@@ -20,6 +20,6 @@ contract C {
// ----
// g() -> 2, 6
// gas irOptimized: 178549
// gas irOptimized: 178177
// gas legacy: 180893
// gas legacyOptimized: 179394
// gas legacyOptimized: 179388
@@ -6,3 +6,4 @@ contract A{
// ====
// SMTEngine: all
// ----
// TypeError 4247: (50-57): Expression has to be an lvalue.
@@ -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.