Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Confusing error message when a getter would return zero values and the compiler refuses to generate it #12302

Closed
benediamond opened this issue Nov 21, 2021 · 1 comment · Fixed by #12361
Labels
easy difficulty good first issue should report better error Error is just badly reported. Should be a proper type error - source is not fine.

Comments

@benediamond
Copy link

benediamond commented Nov 21, 2021

Original title: "unusual behavior with mapping within struct within library".

Description

When a library contains a struct type whose only member is a mapping, and a contract contains a public member of that struct type, then compilation fails with error Internal or recursive type is not allowed for public state variables.. But if you add a further field in the struct (of type uint256 for example), then compilation does not fail. This looks like a bug.

Environment

  • Compiler version: 0.8.10
  • Target EVM version (as per compiler settings): compiler default (London)
  • Framework/IDE (e.g. Truffle or Remix): Remix
  • EVM execution environment / backend / blockchain client:
  • Operating system: MacOS

Steps to Reproduce

Lib.sol

pragma solidity 0.8.10;
library Lib {
    struct MyStruct {
        // uint256 myInt;
        mapping(uint256 => uint256) myMap;
    }
}

A.sol

pragma solidity 0.8.10;
import './Lib.sol';
contract A {
    Lib.MyStruct public myStruct;
}
TypeError: Internal or recursive type is not allowed for public state variables.
 --> contracts/A.sol:6:5:
  |
6 |     Lib.MyStruct public myStruct;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

BUT IF YOU UNCOMMENT the commented line, then it compiles.

@cameel
Copy link
Member

cameel commented Nov 21, 2021

This is not really a bug but a limitation of automatically generated getters:

The mapping and arrays (with the exception of byte arrays) in the struct are omitted because there is no good way to select individual struct members or provide a key for the mapping:

When all members of the struct are omitted, your getter would not return anything and the compiler issues an error. This is by design. I agree that the error message for this is pretty bad and should be changed though.

Related issue: #11369.

@cameel cameel added easy difficulty enhancement good first issue should report better error Error is just badly reported. Should be a proper type error - source is not fine. labels Nov 21, 2021
@cameel cameel changed the title unusual behavior with mapping within struct within library Better error message when a getter would return zero values and the compiler refuses to generate it Nov 21, 2021
@cameel cameel changed the title Better error message when a getter would return zero values and the compiler refuses to generate it Confusing error message when a getter would return zero values and the compiler refuses to generate it Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy difficulty good first issue should report better error Error is just badly reported. Should be a proper type error - source is not fine.
Projects
None yet
2 participants