mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change assertions to align to TypeChecker.
This commit is contained in:
parent
d479c98920
commit
64f0120622
@ -1050,18 +1050,18 @@ void CompilerUtils::convertType(
|
|||||||
}
|
}
|
||||||
case Type::Category::ArraySlice:
|
case Type::Category::ArraySlice:
|
||||||
{
|
{
|
||||||
auto& typeOnStack = dynamic_cast<ArraySliceType const&>(_typeOnStack);
|
|
||||||
solAssert(_targetType.category() == Type::Category::Array, "");
|
solAssert(_targetType.category() == Type::Category::Array, "");
|
||||||
|
auto& typeOnStack = dynamic_cast<ArraySliceType const&>(_typeOnStack);
|
||||||
auto const& targetArrayType = dynamic_cast<ArrayType const&>(_targetType);
|
auto const& targetArrayType = dynamic_cast<ArrayType const&>(_targetType);
|
||||||
solAssert(targetArrayType == *typeOnStack.arrayType().copyForLocation(targetArrayType.location(), false), "");
|
solAssert(typeOnStack.arrayType().isImplicitlyConvertibleTo(targetArrayType), "");
|
||||||
if (!_targetType.dataStoredIn(DataLocation::CallData))
|
solAssert(
|
||||||
return convertType(typeOnStack.arrayType(), _targetType);
|
typeOnStack.arrayType().dataStoredIn(DataLocation::CallData) &&
|
||||||
solUnimplementedAssert(
|
|
||||||
typeOnStack.arrayType().location() == DataLocation::CallData &&
|
|
||||||
typeOnStack.arrayType().isDynamicallySized() &&
|
typeOnStack.arrayType().isDynamicallySized() &&
|
||||||
!typeOnStack.arrayType().baseType()->isDynamicallyEncoded(),
|
!typeOnStack.arrayType().baseType()->isDynamicallyEncoded(),
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
|
if (!_targetType.dataStoredIn(DataLocation::CallData))
|
||||||
|
return convertType(typeOnStack.arrayType(), _targetType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Type::Category::Struct:
|
case Type::Category::Struct:
|
||||||
|
@ -2848,17 +2848,16 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
|
|||||||
}
|
}
|
||||||
else if (_from.category() == Type::Category::ArraySlice)
|
else if (_from.category() == Type::Category::ArraySlice)
|
||||||
{
|
{
|
||||||
solAssert(_from.isDynamicallySized(), "");
|
|
||||||
solAssert(_from.dataStoredIn(DataLocation::CallData), "");
|
|
||||||
solAssert(_to.category() == Type::Category::Array, "");
|
solAssert(_to.category() == Type::Category::Array, "");
|
||||||
|
|
||||||
auto const& fromType = dynamic_cast<ArraySliceType const&>(_from);
|
auto const& fromType = dynamic_cast<ArraySliceType const&>(_from);
|
||||||
auto const& targetType = dynamic_cast<ArrayType const&>(_to);
|
auto const& targetType = dynamic_cast<ArrayType const&>(_to);
|
||||||
|
|
||||||
solAssert(!fromType.arrayType().baseType()->isDynamicallyEncoded(), "");
|
solAssert(fromType.arrayType().isImplicitlyConvertibleTo(targetType), "");
|
||||||
solAssert(
|
solAssert(
|
||||||
*fromType.arrayType().baseType() == *targetType.baseType(),
|
fromType.arrayType().dataStoredIn(DataLocation::CallData) &&
|
||||||
"Converting arrays of different type is not possible"
|
fromType.arrayType().isDynamicallySized() &&
|
||||||
|
!fromType.arrayType().baseType()->isDynamicallyEncoded(),
|
||||||
|
""
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!targetType.dataStoredIn(DataLocation::CallData))
|
if (!targetType.dataStoredIn(DataLocation::CallData))
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
struct S {
|
||||||
|
uint128 p1;
|
||||||
|
uint256[3] a;
|
||||||
|
uint32 p2;
|
||||||
|
}
|
||||||
|
function f(S[] calldata c) internal returns (S[] memory) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
function g(S[] calldata c, uint256 s, uint256 e) public returns (S[] memory) {
|
||||||
|
return f(c[s:e]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function f1(uint256[3][] calldata c) internal returns (uint256[3][] memory) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
function g1(uint256[3][] calldata c, uint256 s, uint256 e) public returns (uint256[3][] memory) {
|
||||||
|
return f1(c[s:e]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// g((uint128, uint256[3], uint32)[], uint256, uint256): 0x60, 1, 3, 4, 55, 1, 2, 3, 66, 66, 2, 3, 4, 77, 77, 3, 4, 5, 88, 88, 4, 5, 6, 99 -> 0x20, 2, 66, 2, 3, 4, 77, 77, 3, 4, 5, 88
|
||||||
|
// g1(uint256[3][], uint256, uint256): 0x60, 1, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> 0x20, 2, 4, 5, 6, 7, 8, 9
|
Loading…
Reference in New Issue
Block a user