[
https://issues.apache.org/jira/browse/GROOVY-12473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18129749#comment-18129749
]
Björn Kautler commented on GROOVY-12473:
----------------------------------------
Maybe I was not fully clear.
There is a {{{}public static final float NaN{}}}.
There is a {{{}public boolean isNaN(){}}}.
There is a {{{}public static boolean isNaN(float v){}}}.
As the last is taking an argument, I'd say it should be out of the equation.
Also, the result is a cast exception because {{Class<Float>}} is tried to be
cast to {{{}Float{}}}.
So this makes me think it selected the *instance* property getter and tries to
apply it on the {{Class}} instance, resulting in the impossible case.
And that cannot be intended, can it? :)
> SC: static compilation in some situation prefers boolean getter over static
> field and produces cast exception
> -------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12473
> URL: https://issues.apache.org/jira/browse/GROOVY-12473
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.23, 3.0.25, 5.0.3, 4.0.33, 5.1.3, 6.0.0
> Reporter: Björn Kautler
> Priority: Major
>
> Given this snippet:
> {code:groovy}
> @groovy.transform.CompileStatic
> def foo() {
> (Float as Class<Float>).NaN
> }
> foo().toString()
> {code}
> It fails at runtime with a class-cast exception, because static compilation
> decides it would be a good idea to interpret the {{NaN}} not as the static
> field, but as {{isNaN()}} call, casting the {{Class<FLoat>}} to {{Float}}
> which fails of course.
> (This might seem like forged example, of course you would usually do
> {{Float.NaN}} which works. Nevertheless it should work and not produce cast
> exception, and if you use {{Float.NaN}} in a Spock assertion with a
> SC-optimized Spock, you get exactly that cast exception)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)