mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow calldata arrays with dynamically encoded base types in TypeChecker.
This commit is contained in:
parent
92cb6cb793
commit
9e32aa7510
@ -366,6 +366,16 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
|||||||
for (ASTPointer<VariableDeclaration> const& var: _function.parameters())
|
for (ASTPointer<VariableDeclaration> const& var: _function.parameters())
|
||||||
{
|
{
|
||||||
TypePointer baseType = type(*var);
|
TypePointer baseType = type(*var);
|
||||||
|
if (auto const* arrayType = dynamic_cast<ArrayType const*>(baseType.get()))
|
||||||
|
{
|
||||||
|
baseType = arrayType->baseType();
|
||||||
|
if (
|
||||||
|
!m_scope->isInterface() &&
|
||||||
|
baseType->dataStoredIn(DataLocation::CallData) &&
|
||||||
|
baseType->isDynamicallyEncoded()
|
||||||
|
)
|
||||||
|
m_errorReporter.typeError(var->location(), "Calldata arrays with dynamically encoded base types are not yet supported.");
|
||||||
|
}
|
||||||
while (auto const* arrayType = dynamic_cast<ArrayType const*>(baseType.get()))
|
while (auto const* arrayType = dynamic_cast<ArrayType const*>(baseType.get()))
|
||||||
baseType = arrayType->baseType();
|
baseType = arrayType->baseType();
|
||||||
|
|
||||||
|
@ -8013,6 +8013,22 @@ BOOST_AUTO_TEST_CASE(struct_named_constructor)
|
|||||||
ABI_CHECK(callContractFunction("s()"), encodeArgs(u256(1), true));
|
ABI_CHECK(callContractFunction("s()"), encodeArgs(u256(1), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(calldata_array)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
contract C {
|
||||||
|
function f(uint[2] calldata s) external pure returns (uint256 a, uint256 b) {
|
||||||
|
a = s[0];
|
||||||
|
b = s[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "C");
|
||||||
|
|
||||||
|
ABI_CHECK(callContractFunction("f(uint256[2])", encodeArgs(u256(42), u256(23))), encodeArgs(u256(42), u256(23)));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(calldata_struct)
|
BOOST_AUTO_TEST_CASE(calldata_struct)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
6
test/libsolidity/syntaxTests/array/calldata.sol
Normal file
6
test/libsolidity/syntaxTests/array/calldata.sol
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
contract Test {
|
||||||
|
function f(uint[3] calldata) external { }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
6
test/libsolidity/syntaxTests/array/calldata_dynamic.sol
Normal file
6
test/libsolidity/syntaxTests/array/calldata_dynamic.sol
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
contract Test {
|
||||||
|
function f(uint[] calldata) external { }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
6
test/libsolidity/syntaxTests/array/calldata_multi.sol
Normal file
6
test/libsolidity/syntaxTests/array/calldata_multi.sol
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
contract Test {
|
||||||
|
function f(uint[3][4] calldata) external { }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
@ -0,0 +1,7 @@
|
|||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
contract Test {
|
||||||
|
function f(uint[][] calldata) external { }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||||
|
// TypeError: (65-82): Calldata arrays with dynamically encoded base types are not yet supported.
|
@ -6,3 +6,4 @@ contract Test {
|
|||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
|
||||||
|
// TypeError: (131-145): Calldata arrays with dynamically encoded base types are not yet supported.
|
||||||
|
Loading…
Reference in New Issue
Block a user