[
https://issues.apache.org/jira/browse/GROOVY-10359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17864222#comment-17864222
]
Eric Milles commented on GROOVY-10359:
--------------------------------------
I created this script to understand the scope of number conversion. TL;DR is
Groovy converts between numbers and primitives with no error or warning.
You can change the type of "b" from "byte" to any of the other types below and
the dynamic runtime happily makes a conversion. With type-checking enabled,
there are errors for possible loss of precision for {{short}}, {{int}},
{{long}}, {{float}}, {{double}} and their wrapper types. Why not {{char}}? It
also states that {{Character}} is inconvertible. Lastly it says
{{BigInteger}}, {{BigDecimal}} and {{AtomicInteger}} are not assignment
compatible. (Groovy 3)
{code:groovy}
byte b = 0
b = (byte) 1
println(b)
println(b.class)
b = (char) 2
println(b)
println(b.class)
b = (short) 3
println(b)
println(b.class)
b = (int) 4
println(b)
println(b.class)
b = (long) 5
println(b)
println(b.class)
b = (float) 6
println(b)
println(b.class)
b = (double) 7
println(b)
println(b.class)
println()
b = (Byte) 1
println(b)
println(b.class)
b = (Character) 2
println(b)
println(b.class)
b = (Short) 3
println(b)
println(b.class)
b = (Integer) 4
println(b)
println(b.class)
b = (Long) 5
println(b)
println(b.class)
b = (Float) 6
println(b)
println(b.class)
b = (Double) 7
println(b)
println(b.class)
b = (BigInteger) 8
println(b)
println(b.class)
b = (BigDecimal) 9.0
println(b)
println(b.class)
b = new java.util.concurrent.atomic.AtomicInteger(10)
println(b)
println(b.class)
{code}
> STC misses type error when involving a variable with a char a declared type
> ---------------------------------------------------------------------------
>
> Key: GROOVY-10359
> URL: https://issues.apache.org/jira/browse/GROOVY-10359
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Minor
>
> I have the following program
> {code:java}
> class Test {
> public static void main(String[] args) {
> char f = (Integer) null;
> }
> }
> {code}
> h3. Actual behaviour
> groovyc compiles this program
> h3. Expected behaviour.
> groovyc should have rejected this program with an error of the form:
> {code}
> error: incompatible types: Integer cannot be converted to char
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)