[
https://issues.apache.org/jira/browse/GROOVY-9979?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-9979:
--------------------------------
Priority: Minor (was: Major)
> Inconsistency in handling of numeric types
> ------------------------------------------
>
> Key: GROOVY-9979
> URL: https://issues.apache.org/jira/browse/GROOVY-9979
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Priority: Minor
>
> I have the following program
> {code:java}
> public class Main {
> public static void foo() {
> final Byte f = (Float) 32.3 // possible loss of precision
> baz((Float) 13.3) // cannot find matching method
> }
>
> public static Byte bar() {
> return (Float) 4324141.4 // does not report error.
> }
> public static void baz(Byte x) {}
> }
> {code}
> In the above program, during the assignment `final Byte f = (Float) 32.3`
> (line 3), I get
> {code:java}
> test.groovy: 4: [Static type checking] - Possible loss of precision from
> java.lang.Float to java.lang.Byte
> @ line 4, column 20.
> final Byte f = (Float) 32.3 // possible loss of precision
> ^1 error
> {code}
> Similarly, when passing a Float value in a function expecting Byte (line 4),
> I get
> {code:java}
> test.groovy: 4: [Static type checking] - Cannot find matching method
> Main#baz(java.lang.Float). Please check if the declared type is correct and
> if the method exists.
> @ line 4, column 5.
> baz((Float) 13.3); // does not report error.
> {code}
>
> However, the compiler does not complain when returning a Float value in a
> function whose return type is Byte (line 8),
>
> Is this inconsistency a bug or a feature?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)