[
https://issues.apache.org/jira/browse/GROOVY-10359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17864224#comment-17864224
]
Eric Milles commented on GROOVY-10359:
--------------------------------------
I think STC is missing {{char}} in the loss of precision checking:
{code:groovy}
@TypeChecked test() {
byte b = 0
println(b)
b = (char)1000
println(b) // prints "-24"
println(b.class)
}
test()
{code}
It does not allow cast from number to {{Character}}, which the runtime does
support:
{code:groovy}
@TypeChecked test() {
print((Character) 2)
}
test()
And there is no warning about the possibility of null:
{code:groovy}
@TypeChecked test(Byte bb) {
byte b = bb
}
test()
{code}
[~blackdrag] [~paulk] Any thoughts on changing one or more of these in STC?
> 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)