Merge pull request #9822 from ethereum/fix-ice-on-returning-string-literal-in-calldata

Mark string literals as not implicitly convertible to calldata arrays
This commit is contained in:
chriseth
2020-09-16 14:23:47 +02:00
committed by GitHub
5 changed files with 42 additions and 0 deletions
@@ -0,0 +1,9 @@
pragma experimental ABIEncoderV2;
contract C {
function f() public pure returns(string[5] calldata) {
return ["h", "e", "l", "l", "o"];
}
}
// ----
// TypeError 6359: (122-147): Return argument type string memory[5] memory is not implicitly convertible to expected type (type of first return variable) string calldata[5] calldata.
@@ -0,0 +1,17 @@
contract C {
function f1() public pure returns(string calldata) {
return "hello";
}
function f2() public pure returns(string calldata) {
return unicode"hello";
}
function f3() public pure returns(bytes calldata) {
return hex"68656c6c6f";
}
}
// ----
// TypeError 6359: (85-92): Return argument type literal_string "hello" is not implicitly convertible to expected type (type of first return variable) string calldata.
// TypeError 6359: (173-187): Return argument type literal_string "hello" is not implicitly convertible to expected type (type of first return variable) string calldata.
// TypeError 6359: (267-282): Return argument type literal_string "hello" is not implicitly convertible to expected type (type of first return variable) bytes calldata.
@@ -0,0 +1,14 @@
contract C {
function g(string calldata _s) public {}
function h(bytes calldata _b) public {}
function f() public {
g("hello");
g(unicode"hello");
h(hex"68656c6c6f");
}
}
// ----
// TypeError 9553: (139-146): Invalid type for argument in function call. Invalid implicit conversion from literal_string "hello" to string calldata requested.
// TypeError 9553: (159-173): Invalid type for argument in function call. Invalid implicit conversion from literal_string "hello" to string calldata requested.
// TypeError 9553: (186-201): Invalid type for argument in function call. Invalid implicit conversion from literal_string "hello" to bytes calldata requested.