Fix InlineArrayType::componentsCommonMobileType function

This commit is contained in:
wechman 2022-08-12 07:52:52 +02:00
parent e4be484047
commit efcf92948c
2 changed files with 34 additions and 5 deletions

View File

@ -2819,12 +2819,9 @@ Type const* InlineArrayType::componentsCommonMobileType() const
Type const* commonType = nullptr;
for (Type const* type: m_components)
commonType =
commonType ?
Type::commonType(commonType, type->mobileType()) :
type->mobileType();
commonType = commonType ? Type::commonType(commonType, type) : type;
return TypeProvider::withLocationIfReference(DataLocation::Memory, commonType);
return TypeProvider::withLocationIfReference(DataLocation::Memory, commonType->mobileType());
}
vector<tuple<string, Type const*>> InlineArrayType::makeStackItems() const

View File

@ -2,9 +2,41 @@ contract C {
function f() public returns (uint256) {
return ([1, 2, 3, 4][2]);
}
function g() public returns (uint256) {
return [7][0];
}
function h(uint i) public returns (int256) {
return [1, -1][i];
}
function k(uint i) public returns (int256) {
return [-2, 2][i];
}
function l(uint i) public returns (int256) {
int8 a = -2;
uint8 b = 3;
return [1, a, b, -1, get()][i];
}
function get() internal returns (int) {
return -2;
}
}
// ====
// compileToEwasm: also
// ----
// f() -> 3
// g() -> 7
// h(uint256): 0 -> 1
// h(uint256): 1 -> -1
// k(uint256): 0 -> -2
// k(uint256): 1 -> 2
// l(uint256): 0 -> 1
// l(uint256): 1 -> -2
// l(uint256): 2 -> 3
// l(uint256): 3 -> -1
// l(uint256): 4 -> -2