groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Afanasiev (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8330) Wrong 'Inconvertible types' error on casting interface
Date Tue, 26 Sep 2017 14:26:00 GMT

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

Alexey Afanasiev updated GROOVY-8330:
-------------------------------------
    Description: 
{code}
import groovy.transform.CompileStatic

interface A1{}
interface A2 extends A1{}
        
class C1 implements A1{}
class C2 extends C1 implements A2 {}
        
@CompileStatic
def m(A2 a2) {
       C1 c1 = (C1) a2 // There is error here now: Inconvertible types: cannot cast A2 to
C1
}
{code}

JLS handle this situation in 5.1.6.1 :
__A narrowing reference conversion exists from reference type S to reference type T
if ......  - S is an interface type, T is a class type, and T does not name a final class.__

  was:
{code}
import groovy.transform.CompileStatic

interface A1{}
interface A2 extends A1{}
        
class C1 implements A1{}
class C2 extends C1 implements A2 {}
        
@CompileStatic
def m(A2 a2) {
       C1 c1 = (C1) a2 // There is error here now: Inconvertible types: cannot cast A2 to
C1
}
{code}

JLS handle this situation in 5.1.6.1 :
_A narrowing reference conversion exists from reference type S to reference type T
if ......  - S is an interface type, T is a class type, and T does not name a final class._


> Wrong 'Inconvertible types' error on casting interface 
> -------------------------------------------------------
>
>                 Key: GROOVY-8330
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8330
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 2.4.12
>            Reporter: Alexey Afanasiev
>
> {code}
> import groovy.transform.CompileStatic
> interface A1{}
> interface A2 extends A1{}
>         
> class C1 implements A1{}
> class C2 extends C1 implements A2 {}
>         
> @CompileStatic
> def m(A2 a2) {
>        C1 c1 = (C1) a2 // There is error here now: Inconvertible types: cannot cast A2
to C1
> }
> {code}
> JLS handle this situation in 5.1.6.1 :
> __A narrowing reference conversion exists from reference type S to reference type T
> if ......  - S is an interface type, T is a class type, and T does not name a final class.__



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message