From efcf92948ceffe65bc59ade11e1a0f78a4fc2d18 Mon Sep 17 00:00:00 2001 From: wechman Date: Fri, 12 Aug 2022 07:52:52 +0200 Subject: [PATCH] Fix InlineArrayType::componentsCommonMobileType function --- libsolidity/ast/Types.cpp | 7 ++-- .../inline_array_index_access_ints.sol | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index c8e606b40..92f9f09fe 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -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> InlineArrayType::makeStackItems() const diff --git a/test/libsolidity/semanticTests/array/indexAccess/inline_array_index_access_ints.sol b/test/libsolidity/semanticTests/array/indexAccess/inline_array_index_access_ints.sol index c1481fc99..f54c960f3 100644 --- a/test/libsolidity/semanticTests/array/indexAccess/inline_array_index_access_ints.sol +++ b/test/libsolidity/semanticTests/array/indexAccess/inline_array_index_access_ints.sol @@ -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