You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Keegan Witt (JIRA)" <ji...@apache.org> on 2015/09/01 20:46:46 UTC

[jira] [Commented] (GROOVY-7557) Inconsistant CompileStatic conversions

    [ https://issues.apache.org/jira/browse/GROOVY-7557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14725874#comment-14725874 ] 

Keegan Witt commented on GROOVY-7557:
-------------------------------------

This relates to the "Numeric assignment documentation" thread on the dev mailing list, which spawned [PR #98|https://github.com/apache/incubator-groovy/pull/98].  During the process of coming up with the documentation, I discovered these inconsistencies.  To reiterate my procedure for getting these was

{code:java}
types = ['boolean', 'Boolean', 'byte', 'Byte', 'short', 'Short', 'char', 'Character', 'int', 'Integer', 'long', 'Long', 'BigInteger', 'float', 'Float', 'double', 'Double', 'BigDecimal']
GroovyClassLoader groovyClassLoader = new GroovyClassLoader()
String[] params = new String[1]
for (def fromType in types) {
    for (def toType in types) {
        def code = """class Main{static void main(def args){
        $fromType foo = 0
        $toType bar = foo
        }}"""
        try {
            groovyClassLoader.parseClass("@groovy.transform.CompileStatic\n" + code).getMethod("main", String[].class).invoke(null, params)
            if (fromType == toType) {
                println "${fromType}\t${toType}\t-"
                continue
            }
            if (fromType.toLowerCase().startsWith(toType) || toType.toLowerCase().startsWith(fromType)) {
                println "${fromType}\t${toType}\tB"
                continue
            }
            if (toType.toLowerCase() == 'boolean') {
                println "${fromType}\t${toType}\tT"
                continue
            }
            println "${fromType}\t${toType}\tY"
        } catch(e1) {
            try {
                groovyClassLoader.parseClass(code).getMethod("main", String[].class).invoke(null, params)
                println "${fromType}\t${toType}\tD"
            } catch(e2) {
                println "${fromType}\t${toType}\tN"
            }
        }
    }
}
{code}

Obviously most truncation cases aren't covered by that code, so I manually touched those up for the purposes of the documentation.

> Inconsistant CompileStatic conversions
> --------------------------------------
>
>                 Key: GROOVY-7557
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7557
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Keegan Witt
>            Assignee: Cédric Champeau
>
> Work with {{CompileStatic}}, but I don't think they should
> * char -> byte
> * char -> short
> * int -> char
> * Integer -> char
> * long -> char
> * Long -> char
> * Float -> Byte
> * Double -> Byte
> * Short -> Byte
> * Long -> Short
> * Long -> Integer
> * Float -> Integer
> * Double -> Integer
> * Float -> Long
> * Double -> Long
> * Double -> Float
> Don't work with {{CompileStatic}}, but I think should
> * char -> Character
> * Character -> char
> * char -> Integer
> * Character -> int
> * Character -> Integer
> * char -> Long
> * Character -> long
> * Character -> Long
> * Character -> float
> * char -> Float
> * Character -> Float



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)