[
https://issues.apache.org/jira/browse/GROOVY-12105?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18091735#comment-18091735
]
Paul King commented on GROOVY-12105:
------------------------------------
[~emilles] That is what I'd like to lock down. The issue title reflects that
neither the spec nor implementation lock this down. The recommendation is to
make it a compile error as per the proposed PR and proposed GEP-22 change:
https://github.com/apache/groovy/pull/2629
https://github.com/apache/groovy-website/pull/80 (also covers GROOVY-12104)
> Unqualified super.m(...) from a static trait method throws
> MissingMethodException — should be a compile error or walk the trait chain
> -------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12105
> URL: https://issues.apache.org/jira/browse/GROOVY-12105
> Project: Groovy
> Issue Type: Bug
> Reporter: Paul King
> Priority: Major
>
> Inside a trait STATIC method, an unqualified `super.m(...)` call does
> not walk the trait chain documented for the instance-method case
> (GEP-22 § "this, super, and stackable traits" item 2). The call
> compiles successfully but throws MissingMethodException at runtime.
> Minimal reproducer:
> {code:groovy}
> trait Base { static String m() { 'Base' } }
> trait V extends Base {
> static String m() { 'V' }
> static callSuper() { super.m() } // unqualified, from static
> }
> class Impl implements V { }
> Impl.callSuper()
> {code}
> Expected: either resolve to Base.m (matching the spec's "walks the
> trait chain" semantic for the instance case) or reject at compile
> time as an unsupported construct.
> Actual (consistent across 4.0.32, 5.0.6, 6.0.0-alpha-1):
> java.lang.MissingMethodException: No signature of method:
> static Base.m() is applicable for argument types: () values: []
> Contrast: the instance-method version of the same shape
> (without `static`) works as the spec documents — returns 'Base'.
> Plain Java/Groovy `super.m()` for class statics works normally
> (returns the parent class's m()), so the limitation is specific to
> trait static methods.
> *Recommended fix*: either implement the trait-chain walk for statics
> (symmetric with the instance-method case), or reject at compile time
> with a clear error pointing to `T.super.m(...)` as the explicit form.
> The latter is simpler and matches the recommendation in the GEP-22 v5
> draft (§ "this, super, and stackable traits" item 4, already drafted
> as part of the GEP-22 PR companion to this ticket).
> *Test coverage*: row 15 in
> src/test/groovy/org/codehaus/groovy/transform/traitx/TraitStaticDispatchMatrix.groovy
> is currently @NotYetImplemented asserting the compile-error
> end-state; will flip red when this ticket is resolved.
> *Related*: GROOVY-11985, GROOVY-12093, JIRA #1 (T.this in trait body).
> Both surfaced during empirical sweep for Grails alternatives.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)