Skip to content

Mapping:The getter automatically generated by the mapping has a bug. #15979

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

Open
Un96 opened this issue Apr 3, 2025 · 1 comment
Open

Mapping:The getter automatically generated by the mapping has a bug. #15979

Un96 opened this issue Apr 3, 2025 · 1 comment
Labels

Comments

@Un96
Copy link

Un96 commented Apr 3, 2025

Description

The getter automatically generated by the mapping has a bug.

Environment

Remix 0.8.29

Steps to Reproduce

When I use " mapping(address => uint256[]) public holderCertificates;",the getters automatically generated by the mapping do not support getting arrays by address.

Image

I have to manually construct the getter to retrieve the data.

Image
@Un96 Un96 added the bug 🐛 label Apr 3, 2025
@singhyash05
Copy link

Hi @Un96, thanks for the follow‑up—what you’re seeing is actually by design, not a bug:
Auto‑getter signature
mapping(address => uint256[]) public holderCertificates;


the compiler only emits:
function holderCertificates(address _holder, uint256 _idx) external view returns (uint256);
i.e. you must supply both the holder’s address and an array index to fetch a single element. There is no holderCertificates(address) or length getter.


How to expose length or the full array
If you need to read the array length or return the entire list, add custom functions, for example:

/// @notice Get the number of certificates for a holder
function getHolderCertificatesLength(address _holder) external view returns (uint256) {
  return holderCertificates[_holder].length;
}

/// @notice Get all certificate IDs for a holder
function getHolderCertificates(address _holder) external view returns (uint256[] memory) {
  return holderCertificates[_holder];
}

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

No branches or pull requests

2 participants