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/01/03 16:13:00 UTC

[jira] [Updated] (GROOVY-10339) STC instantiates parameterized function with a wrong type leading to unsoundness

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

Eric Milles updated GROOVY-10339:
---------------------------------
    Fix Version/s: 3.0.15

> STC instantiates parameterized function with a wrong type leading to unsoundness
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-10339
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10339
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-rc-1, 3.0.15
>
>
> I have the following program
> {code:java}
> class Test {
>   static <T> T bar(T x, T y) { return x; }
>   static String m() { return ""; }
>   static void main(String[] args) {
>      Integer x = bar(m(), 1); // STC misses the error.
>   }
> }
> {code}
> h3. Actual behaviour
> groovyc incorrectly accepts the above program, although it contains a type error at line7. This leads to the following exception at runtime:
> {code}
> Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '' with class 'java.lang.String' to class 'java.lang.Integer'
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:179)
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:294)
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:251)
>         at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
>         at Test.main(test.groovy:7)
> {code}
> h3. Expected behaviour
> The compiler should have rejected the program.
> Tested against master.



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