[ 
https://issues.apache.org/jira/browse/GROOVY-9786?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-9786:
--------------------------------
    Language: groovy

> 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.20.10#820010)

Reply via email to