[
https://issues.apache.org/jira/browse/GROOVY-11760?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-11760.
----------------------------------
Resolution: Information Provided
STC figures the result type of "1f / 1" as double -- this is not new. If you
assigned the division to a local variable, like "float value = 1f / 1", you'd
get the error in Groovy 4. Groovy 5 added precision checks to return
statements, which is why you get the error now.
> @CompileStatic method triggers static type checking error in Groovy 5 but not
> Groovy 4
> --------------------------------------------------------------------------------------
>
> Key: GROOVY-11760
> URL: https://issues.apache.org/jira/browse/GROOVY-11760
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 5.0.1
> Reporter: Stephen Albrecht
> Assignee: Eric Milles
> Priority: Major
>
> This script executes in Groovy 4.0.28 but fails to compile in 5.0.1.
> I would expect Groovy 5 to be able to handle this type coercion the same as
> Groovy 4
> {code:java}
> import groovy.transform.CompileStatic
> @CompileStatic
> float getFoo() { 1f / 1 }
> foo{code}
> Groovy 4.0.28
> {code:java}
> Result: 1.0{code}
> Groovy 5.0.1
> {code:java}
> [Static type checking] - Possible loss of precision from double to float
> at line: 5, column: 4{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)