[ 
https://issues.apache.org/jira/browse/GROOVY-8380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16252863#comment-16252863
 ] 

Jochen Theodorou commented on GROOVY-8380:
------------------------------------------

Please bear in mind, that an assignment in dynamic Groovy is no substitute for 
a method parameter. In Groovy the assignment involves an implicit cast, that is 
not the case for a method call. So it is always legal to assign a number typed 
value to a variable with another number type, even if that means a loss of 
precision. As for what types are compatible with a Long/long typed parameter 
you should take a look at LongCachedClass#isAssignableFrom.You will see there, 
that Double, Float and BigDecimal are no candidates. And if you then look at 
DoubleCachedClass and FloatCachedClass, you will that loss of precision is 
really no factor here. In fact if you look at IntegerCachedClass you will see 
that it is perfectly legal to pass an BigInteger or Long for an int parameter.

What we did not do in dynamic Groovy is allow floating points typed arguments 
for integer types parameters. Why that is... frankly I have no idea.That goes 
back to March 2008 at least. But I donĀ“t think that was a change, since even 
groovy-beta-9 fails to call a method with a long parameter using a BigDecimal 
argument.

Static Groovy has the "no loss of precision" rule, thus here it should be even 
more clear what is required.

> Regression in 2.4.13 (snapshot) 62615249161b233b1827d5950671d3a83007cd9f
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-8380
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8380
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.13
>         Environment: any
>            Reporter: Patric Bechtel
>            Priority: Critical
>
> This used to work up to 2.4.12:
> {code}
> @groovy.transform.CompileStatic
> class bla {
>    static void main(String[] args) {
>       println new Long( 5 / 3 )
>    }
> }
> {code}
> starting with 2.4.13, it gives this error message:
> {noformat}
> bla.groovy: 4: [Static type checking] - Cannot find matching method 
> java.lang.Long#<init>(java.math.BigDecimal). Please check if the declared 
> type is right and if the method exists.
>  @ line 4, column 15.
>          println new Long( 5 / 3 )
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to