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

Remove unneeded read_only check for Array const operator #103999

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YYF233333
Copy link
Contributor

After checking related PRs, I believe these checks are redundant. The read_only check in ConstIterator comes from #86518, intended to be consistent with the subscript operator, which was added in #61127 (read-only Array), based on #61087 (read-only Dictionary). However, const Variant &Dictionary::operator[] does not have a read_only check (not added in #61087 or subsequent PRs).

Even if these checks are removed, the compiler will still prevent any modifications to container elements through these interfaces, so I think this change is safe.

@YYF233333 YYF233333 requested a review from a team as a code owner March 11, 2025 23:28
Copy link
Contributor

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea!

I had to think for a short bit if there are any risks — but I can't really think of any caveats.

There are Variant types that ignore const (e.g. Ref<Object> which even as const allows accessing the underlying Object in a mutable manner), but this PR doesn't really change anything about that. The important part is the Variant contents themselves are kept intact — which should be the case here.

Note: This addresses part of #93702

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

Successfully merging this pull request may close these issues.

3 participants