[ 
https://issues.apache.org/jira/browse/GROOVY-7994?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15650476#comment-15650476
 ] 

Paul King edited comment on GROOVY-7994 at 11/9/16 10:15 AM:
-------------------------------------------------------------

A slightly revised snippet showing that normal and anonymous inner classes are 
affected:
{code}
import groovy.transform.CompileStatic

@CompileStatic
class Outer {
    String getName() { "sally" }
    class Inner {
        String igo() { new Other(name).text + new Other(getName()).text }
    }
    def makeAIC() {
        println new Other(name).text + new Other(getName()).text
        new Object() {
            String go() { new Other(name).text + new Other(getName()).text }
        }
    }
}

@CompileStatic
class Other {
    public final String text
    Other(Object object) { text = "Object:$object|" }
    Other(String string) { text = "String:$string|" }
}

def o = new Outer()
println o.makeAIC().go()
println new Outer.Inner(o).igo()
{code}


was (Author: paulk):
A slightly revised snippet showing that normal and anonymous inner classes are 
affected:
{code}
import groovy.transform.CompileStatic

@CompileStatic
class Outer {
    String getName() { "sally" }
    class Inner {
        String igo() {
            new Other(name).text + new Other(getName()).text
        }
    }
    def doSomething() {
        println new Other(name).text + new Other(getName()).text
        new Object() {
            String go() {
                new Other(name).text + new Other(getName()).text
            }
        }
    }
}

@CompileStatic
class Other {
    public final String text
    Other(Object object) { text = "Object:$object|" }
    Other(String string) { text = "String:$string|" }
}

def o = new Outer()
def aic = o.doSomething()
println aic.go()
def inner = new Outer.Inner(o)
println inner.igo()
{code}

> Anonymous inner class believes protected method in parent's superclass 
> returns Object
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7994
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7994
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>            Reporter: James Kleeh
>
> The below will execute the constructor on `Other` that takes an `Object`, 
> even though `getName()` returns a `String`.
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Parent {
>     protected String getName() {
>         "sally"
>     }
> }
> @CompileStatic
> class Child extends Parent {
>     Inner doSomething() {
>         return new Inner() {
>             void go() {
>                 new Other(name)
>             }
>         }
>     }
> }
> @CompileStatic
> class Other {
>     Other(Object object) {
>         println "called with other"
>     }
>     Other(String string) {
>         println "called with string"
>     }
> }
> @CompileStatic
> abstract class Inner {
>     abstract void go()
> }
> Inner inner = new Child().doSomething()
> inner.go()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to