You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/04/15 16:05:00 UTC

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

     [ https://issues.apache.org/jira/browse/GROOVY-10912?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-10912:
---------------------------------
    Priority: Minor  (was: Major)

> 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
>            Priority: Minor
>
> 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)