Skip to content

GROOVY-8283: field hides getter of super class (not interface) #1767

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

Merged
merged 6 commits into from
Jul 31, 2025

Conversation

eric-milles
Copy link
Member

@eric-milles eric-milles commented Aug 19, 2022

For the dynamic side of 8283, field can be selected in MetaClassImpl. If access method is declared by an interface, the interface method is the one indexed so must be considered pervasive in the type hierarchy (cannot be safely hidden). Not sure if this kind of name hiding should be extended to inner classes; hopefully the commit is enough of a first step to determine if this protocol should be changed or left alone.

@blackdrag @paulk-asert

TODO:

  • STC selection of field vs setter (verify what StaticTypeCheckingVisitor does vs MetaClassImpl)
  • static compiler classgen -- I think it currently selects the method

https://issues.apache.org/jira/browse/GROOVY-8283

@asfgit asfgit force-pushed the GROOVY-8283 branch 2 times, most recently from fb192a5 to 8324f8b Compare April 28, 2024 01:59
@eric-milles
Copy link
Member Author

@blackdrag @paulk-asert If I refresh the branch, do you think this is viable? The test case should illustrate the new hiding behavior.

@asfgit asfgit force-pushed the GROOVY-8283 branch 2 times, most recently from fe14c7f to ec44e38 Compare October 29, 2024 14:40
@eric-milles
Copy link
Member Author

For circumstances that go through ScriptBytecodeAdapter, the sender class is not propagated to MetaClassImpl. Access checks give different results, since the sender is re-mapped to the object.

            package p
            class A {}
            class B {}
            class C {
                boolean setter
                protected A foo = new A()
                A getFooA() { return this.@foo }
                void setFoo(A a) { setter = true; this.@foo = a }
            }
            class D extends C {
                protected B foo = new B() // hides A#foo; should hide A#setFoo in subclasses
                B getFooB() { return this.@foo }
            }
import p.*
            class E extends D {}
            def e = new E()
            e.foo = null // not the field from this perspective
            assert e.setter // fails

@apache apache deleted a comment from codecov-commenter Jul 16, 2025
@eric-milles eric-milles marked this pull request as ready for review July 16, 2025 20:05
@codecov-commenter
Copy link

codecov-commenter commented Jul 16, 2025

Codecov Report

Attention: Patch coverage is 78.78788% with 14 lines in your changes missing coverage. Please review.

Project coverage is 68.0836%. Comparing base (6db9b27) to head (d068ecd).

Files with missing lines Patch % Lines
...codehaus/groovy/runtime/ScriptBytecodeAdapter.java 64.7059% 5 Missing and 1 partial ⚠️
src/main/java/groovy/lang/MetaClassImpl.java 82.7586% 1 Missing and 4 partials ⚠️
...ovy/classgen/asm/sc/StaticTypesCallSiteWriter.java 60.0000% 0 Missing and 2 partials ⚠️
...roovy/transform/stc/StaticTypeCheckingVisitor.java 93.3333% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #1767        +/-   ##
==================================================
- Coverage     68.0868%   68.0836%   -0.0032%     
- Complexity      29190      29210        +20     
==================================================
  Files            1377       1377                
  Lines          114141     114164        +23     
  Branches        19796      19806        +10     
==================================================
+ Hits            77715      77727        +12     
- Misses          30093      30100         +7     
- Partials         6333       6337         +4     
Files with missing lines Coverage Δ
...roovy/transform/stc/StaticTypeCheckingVisitor.java 87.7031% <93.3333%> (+0.0384%) ⬆️
...ovy/classgen/asm/sc/StaticTypesCallSiteWriter.java 76.1317% <60.0000%> (-0.1677%) ⬇️
src/main/java/groovy/lang/MetaClassImpl.java 78.2848% <82.7586%> (-0.0265%) ⬇️
...codehaus/groovy/runtime/ScriptBytecodeAdapter.java 68.6603% <64.7059%> (-1.0958%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses GROOVY-8283, implementing field hiding behavior where a field in a subclass can hide a getter method of its superclass (but not interface methods). The changes ensure consistent behavior across dynamic execution, static type checking, and static compilation contexts.

Key changes include:

  • Enhanced field visibility logic in MetaClassImpl to properly handle field shadowing of superclass getters
  • Updated static type checking to consider field accessibility when selecting between fields and getter methods
  • Modified bytecode generation to respect field hiding rules during property access

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/test/groovy/bugs/Groovy8283.groovy Comprehensive test suite covering field/property shadowing scenarios across dynamic, type-checked, and compile-static contexts
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java Enhanced property resolution logic to handle field accessibility and getter method selection with bridge method filtering
src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java Updated property access methods to handle missing property exceptions and sender class context properly
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java Added field hiding checks in static compilation to prevent getter usage when field should take precedence
src/main/java/groovy/lang/MetaClassImpl.java Core field visibility logic implementation with new isVisibleProperty method to determine when fields should hide superclass getters

@eric-milles eric-milles merged commit 4dbda66 into master Jul 31, 2025
55 of 56 checks passed
@eric-milles eric-milles deleted the GROOVY-8283 branch July 31, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants