Repository navigation
GROOVY-12484: STC: method and constructor calls on an inaccessible ty… - #3019
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3019 +/- ##
==================================================
+ Coverage 73.6047% 73.6100% +0.0052%
- Complexity 42348 42356 +8
==================================================
Files 1657 1657
Lines 145708 145718 +10
Branches 27498 27501 +3
==================================================
+ Hits 107248 107263 +15
+ Misses 28479 28477 -2
+ Partials 9981 9978 -3
🚀 New features to boost your workflow:
|
daniellansun
left a comment
There was a problem hiding this comment.
Thanks for aligning STC with the existing inaccessible-type checks for fields, and for documenting the JLS 6.6.1 angle in the comments.
Observations:
-
Guarding constructor selection with
!call.isSpecialCall()andhasAccessToClass(...)looks correct so thatthis/superconstruction is not wrongly rejected whilenewon a package-private type from outside is. -
For method calls, keying the check off
ClassExpressionand the chosen receiver (rather than only the method's modifiers) matches the "qualifying type must be accessible" rule. ThePub.inherited()case in the tests is a good regression guard for that distinction. -
Leaving dynamic dispatch and class-literal /
Classmethod usage alone is helpful; the tests make that boundary clear. -
Optional follow-up (not blocking): are instance calls whose static type is inaccessible but not written as a
ClassExpressionalready covered elsewhere, or intentionally out of scope for this ticket? Either way is fine; I mainly want to confirm the intended surface.
Groovy12484 is a clear, minimal suite for the behavior change.
…pe compile and fail at runtime with IllegalAccessError
b98aab2 to
ceb466e
Compare
|
Thanks Jochen. You're right that STC doesn't support an extension or DGM method acting as a constructor, so nothing stops the constructor check from coming earlier. I've checked the code and the runtime:
So the current revised version moves the constructor check ahead of lookup. For an inaccessible type, STC now reports "Cannot access constructor of class: T" and skips lookup altogether. It still checks the arguments the same way it does when no constructor matches. A new test covers For method calls, I don't think the check can go inside Fixtures (all Java, precompiled): in package
Rows 4 and 5 are why the check has to use the type written at the call site rather than the declaring class. Rows 1–3 are the cases the ticket is about. Row 6 is a deliberate difference from Java, because Groovy lets you use an inaccessible class as a Rows 7–9 are the case Daniel asked about, a call on an expression whose type is inaccessible. Java rejects all of them, even |
🚨 All tests passed but jobs failed 🚨Failed Jobs without Test Failures❌ Build and test / lts (17, macos-latest) 🏷️ Commit: ceb466e Rerun ControlsClick the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
daniellansun
left a comment
There was a problem hiding this comment.
Thanks for the follow-up on tip ceb466e.
Since my earlier comment: moving the constructor accessibility check ahead of lookup addresses Jochen’s point cleanly, and testConstructorCallRejectedBeforeLookup makes the diagnostic improvement concrete (Cannot access constructor instead of a misleading “no matching constructor”). I agree STC has no DGM-as-constructor path, so the earlier check is safe.
On the optional question from last time — instance calls whose static type is inaccessible but not written as a ClassExpression — your table (rows 7–9) answers it well. Leaving those for a follow-up, while keeping the ClassExpression / constructor cases in this ticket, is a sensible boundary; I will not re-litigate that here.
The Pub.inherited() and class-literal / Class method exemptions remain the right compatibility posture for this change. No further blocking comments from me on this tip.
…pe compile and fail at runtime with IllegalAccessError