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 2023/01/21 16:53:00 UTC

[jira] [Created] (GROOVY-10912) Inconsistency in the treatment of primitives values when passed as call arguments

Thodoris Sotiropoulos created GROOVY-10912:
----------------------------------------------

             Summary: Inconsistency in the treatment of primitives values when passed as call arguments
                 Key: GROOVY-10912
                 URL: https://issues.apache.org/jira/browse/GROOVY-10912
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program

{code}
class Test {
    void test() {
      char c = 'c' // works
      double e = 10.0; // works

      Character v = Character.valueOf('c'); // 'c' is treated as String
      Double d = Double.valueOf(10.0);  // 10.0 is treated as BigDecimal
    }
}
{code}


h3. Actual behavior

{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 4: [Static type checking] - Cannot find matching method java.lang.Character#valueOf(java.lang.String). Please check if the declared type is correct and if the method exists.
 @ line 4, column 21.
         Character v = Character.valueOf('c');
                       ^

test.groovy: 5: [Static type checking] - Cannot find matching method java.lang.Double#valueOf(java.math.BigDecimal). Please check if the declared type is correct and if the method exists.
 @ line 5, column 18.
         Double d = Double.valueOf(10.0);
                    ^

2 errors
{code}

h3. Expected behavior

Compile successfully


Tested against master (commit: 89de534b77e2321d46e6a9821628331693c7aae2)

The above test case demonstrates an inconsistency in the treatment of primitive values. For example,  the constant "10.0" is treated as something of type double when the constant is assigned to a double variable. However, the same constant is not treated as something of type double when it is passed as argument to a function parameter of type double.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)