Skip to content

Arrays are ignored from structs in automatically generated getters #11067

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
m1cm1c opened this issue Mar 8, 2021 · 1 comment
Closed

Arrays are ignored from structs in automatically generated getters #11067

m1cm1c opened this issue Mar 8, 2021 · 1 comment

Comments

@m1cm1c
Copy link

m1cm1c commented Mar 8, 2021

Description

Arrays are ignored from structs in automatically generated getters.

Environment

  • Compiler version: 0.8.2
  • Target EVM version (as per compiler settings): default
  • Framework/IDE (e.g. Truffle or Remix): none
  • EVM execution environment / backend / blockchain client: none
  • Operating system: Manjaro (Linux 5.4)

Steps to Reproduce

Write the following code into a file named ExampleContract.sol:

pragma solidity ^0.8.2;

contract ExampleContract {
    struct Foo {
        uint256 a;
        address[] b;
    }
    
    Foo public foo;
    
    function bar() public view {
        (address a, address[] memory b) = this.foo();
    }
}

Run: solc ExampleContract.sol

The output will be:

Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> ExampleContract.sol

Error: Different number of components on the left hand side (2) than on the right hand side (1).
  --> ExampleContract.sol:12:9:
   |
12 |         (address a, address[] memory b) = this.foo();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error: Type uint256 is not implicitly convertible to expected type address.
  --> ExampleContract.sol:12:9:
   |
12 |         (address a, address[] memory b) = this.foo();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@leonardoalt
Copy link
Member

@m1cm1c this is intended behavior, as pointed out in https://docs.soliditylang.org/en/v0.8.2/contracts.html#getter-functions.
The array itself cannot be returned in its entirety, to avoid unbounded gas costs. If the array is not inside a struct, its getter is a function that takes the index as an argument. When the array is inside a struct, there's no simple way to give the index to the struct's getter, similar to the mapping inside struct example in the link above.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants