[
https://issues.apache.org/jira/browse/GROOVY-12601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140524#comment-18140524
]
ASF GitHub Bot commented on GROOVY-12601:
-----------------------------------------
codeconsole commented on PR #3128:
URL: https://github.com/apache/groovy/pull/3128#issuecomment-6717051096
@daniellansun I can't re-run jobs on apache/groovy, so I merged current
master (492ae79db4) to get a fresh run, which also brings in the Windows Gradle
cache fix (#3110). `VirtualAnnotationTest` passes locally on the merge.
On #3121: both PRs add `onMethodSelection(Expression, MethodNode)` to
`TraitTypeCheckingExtension`. Git merges the two cleanly into a class with two
such methods, which does not compile. Whichever lands second keeps one method,
with this PR's `MethodCallExpression` branch followed by #3121's
`PropertyExpression` branch. `VirtualAnnotationTest` also conflicts, as two
test blocks added at the same place; the fix there is to keep both. On a local
merge of the two that way, with #3121's latest commit, `traitx.*` and
`groovy.transform.stc.*` pass.
> SC calls the java.lang.Class method instead of a @Virtual trait static method
> of the same name
> ----------------------------------------------------------------------------------------------
>
> Key: GROOVY-12601
> URL: https://issues.apache.org/jira/browse/GROOVY-12601
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {code:groovy}
> import groovy.transform.Virtual
> @groovy.transform.CompileStatic
> trait T {
> @Virtual static String getName() { 'trait' }
> static String sm() { getName() }
> }
> class C implements T { static String getName() { 'impl' } }
> class D implements T {}
> assert C.sm() == 'impl'
> assert D.sm() == 'trait'
> {code}
> Actual: {{C.sm()}} returns {{'C'}} and {{D.sm()}} returns {{'D'}}. The trait
> calls {{Class.getName()}}. The same happens for other {{Class}} and DGM names
> such as {{getSimpleName}}, {{isInterface}}, {{getModifiers}} and {{dump}}. A
> {{@Virtual static Object cast(Object)}} fails with a {{ClassCastException}}.
> It also happens from instance trait methods and for a {{@Virtual}} static of
> a super trait.
> Expected: {{'impl'}} and {{'trait'}}, as dynamic Groovy and {{@TypeChecked}}
> give.
> The trait transformation rewrites the call to a call on the static self (a
> Class) and marks it for dynamic dispatch. Static type checking finds
> {{Class.getName()}} on that receiver, so the trait type checking extension is
> never asked and static compilation binds the call to the {{Class}} method.
> Seen in 6.0.0 (the first version with @Virtual).
> PR: https://github.com/apache/groovy/pull/3128
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)