You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2021/03/11 14:22:00 UTC

[jira] [Created] (GROOVY-9979) Inconsistency in handling of numeric types

Thodoris Sotiropoulos created GROOVY-9979:
---------------------------------------------

             Summary: 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


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) // does not report error.
  }
  
  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`, 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}
However, the compiler does not complain when returning a Float value in a function whose return type is Byte (line 8), or passing a Float value in a function expecting Byte (line 4).

 

Is this inconsistency a bug or a feature?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)