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 2020/12/31 21:37:00 UTC
[jira] [Updated] (GROOVY-9786) SC: cast exception for variable
assigned within conditional blocks
[ https://issues.apache.org/jira/browse/GROOVY-9786?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-9786:
--------------------------------
Fix Version/s: 2.5.15
> SC: cast exception for variable assigned within conditional blocks
> ------------------------------------------------------------------
>
> Key: GROOVY-9786
> URL: https://issues.apache.org/jira/browse/GROOVY-9786
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.13
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Major
> Fix For: 3.0.7, 4.0.0-alpha-2, 2.5.15
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Consider the following:
> {code:groovy}
> interface Zero {
> def m()
> }
> class One implements Zero {
> def m() { 'One' }
> }
> class Two implements Zero {
> def m() { 'Two' }
> }
> boolean aaa() { false }
> boolean bbb() { true }
> @groovy.transform.CompileStatic
> void test() {
> Zero x
> if (aaa()) {
> x = new One()
> } else if (bbb()) {
> x = new Two()
> }
> x.m() // GroovyCastException: Cannot cast object 'Two@654d8173' with class 'Two' to class 'One'
> }
> test()
> {code}
> This case was recently converted from dynamic groovy -- where it executes fine -- to {{@CompileStatic}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)