[jira] [Commented] (GROOVY-11014) CompileStatic & Elvis operator: Cannot assign literal value of type (java.lang.Number or java.lang.Comparable) to variable of type double
[ https://issues.apache.org/jira/browse/GROOVY-11014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17782255#comment-17782255 ] Eric Milles commented on GROOVY-11014: -- Similar issues: GROOVY-11006, GROOVY-10359, GROOVY-10095, GROOVY-8488, GROOVY-8325 > CompileStatic & Elvis operator: Cannot assign literal value of type > (java.lang.Number or java.lang.Comparable) to variable of type double > - > > Key: GROOVY-11014 > URL: https://issues.apache.org/jira/browse/GROOVY-11014 > Project: Groovy > Issue Type: Bug > Components: Compiler >Affects Versions: 4.0.5 >Reporter: Jason Garrett >Assignee: Eric Milles >Priority: Minor > Fix For: 5.0.0-alpha-3, 4.0.16 > > > {code:java} > import groovy.transform.CompileStatic > @CompileStatic > class ElvisLiteralAssign { > Double x = null > double y = x?.doubleValue() ?: 0 > } {code} > This class fails to compile with error: [Static type checking] - Cannot > assign value of type (java.lang.Number or java.lang.Comparable) to variable > of type double > This affects at least 4.0.10 and 4.0.11, and does not affect 3.0.16 or 3.0.17. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (GROOVY-11014) CompileStatic & Elvis operator: Cannot assign literal value of type (java.lang.Number or java.lang.Comparable) to variable of type double
[ https://issues.apache.org/jira/browse/GROOVY-11014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17782152#comment-17782152 ] Eric Milles commented on GROOVY-11014: -- Before Groovy 4.0.5, there's a block in {{WideningCategories}} for this: {code:java} if (isNumberType(a.redirect()) && isNumberType(b.redirect())) { ClassNode ua = getUnwrapper(a); ClassNode ub = getUnwrapper(b); Integer pa = NUMBER_TYPES_PRECEDENCE.get(ua); Integer pb = NUMBER_TYPES_PRECEDENCE.get(ub); if (pa != null && pb != null) { return (pa <= pb ? a : b); } } {code} > CompileStatic & Elvis operator: Cannot assign literal value of type > (java.lang.Number or java.lang.Comparable) to variable of type double > - > > Key: GROOVY-11014 > URL: https://issues.apache.org/jira/browse/GROOVY-11014 > Project: Groovy > Issue Type: Bug > Components: Compiler >Affects Versions: 4.0.5 >Reporter: Jason Garrett >Priority: Minor > > {code:java} > import groovy.transform.CompileStatic > @CompileStatic > class ElvisLiteralAssign { > Double x = null > double y = x?.doubleValue() ?: 0 > } {code} > This class fails to compile with error: [Static type checking] - Cannot > assign value of type (java.lang.Number or java.lang.Comparable) to variable > of type double > This affects at least 4.0.10 and 4.0.11, and does not affect 3.0.16 or 3.0.17. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (GROOVY-11014) CompileStatic & Elvis operator: Cannot assign literal value of type (java.lang.Number or java.lang.Comparable) to variable of type double
[ https://issues.apache.org/jira/browse/GROOVY-11014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17717772#comment-17717772 ] Eric Milles commented on GROOVY-11014: -- You should be able to write "0" as "0d" or "0.0" or "(double) 0" and it should make the necessary leap. There are a number of open issues like this where the addition of a ternary puts a level of indirection between source and target. STC tries to blend the two operand types when processing a ternary (elvis or otherwise): https://github.com/apache/groovy/blob/0fbda9b93eb600601dc2dd9b38389ca571310323/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L4220 > CompileStatic & Elvis operator: Cannot assign literal value of type > (java.lang.Number or java.lang.Comparable) to variable of type double > - > > Key: GROOVY-11014 > URL: https://issues.apache.org/jira/browse/GROOVY-11014 > Project: Groovy > Issue Type: Bug > Components: Compiler >Affects Versions: 4.0.10, 4.0.11 >Reporter: Jason Garrett >Priority: Minor > > {code:java} > import groovy.transform.CompileStatic > @CompileStatic > class ElvisLiteralAssign { > Double x = null > double y = x?.doubleValue() ?: 0 > } {code} > This class fails to compile with error: [Static type checking] - Cannot > assign value of type (java.lang.Number or java.lang.Comparable) to variable > of type double > This affects at least 4.0.10 and 4.0.11, and does not affect 3.0.16 or 3.0.17. -- This message was sent by Atlassian Jira (v8.20.10#820010)