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

Scott Murphy Heiberg updated GROOVY-12510:
------------------------------------------
    Description: 
A private method is not inherited (JLS 8.2), so it cannot be called through a 
receiver whose type is a subclass:

{code:groovy}
class Outer {
    static class Base { private String im() { 'im' } }
    static class Sub extends Base {}

    @groovy.transform.TypeChecked static tc() { new Sub().im() }
    @groovy.transform.CompileStatic static cs() { new Sub().im() }
    static dyn() { new Sub().im() }
}
{code}

* {{Outer.dyn()}} throws {{MissingMethodException}}: "No signature of method: 
im for class: Outer$Sub is applicable for argument types: ()"
* {{Outer.tc()}} compiles, then throws the same {{MissingMethodException}}
* {{Outer.cs()}} compiles and calls {{Base.im()}} directly
* javac rejects the equivalent Java: "cannot find symbol, symbol: method im(), 
location: class Sub"

The type checker should reject the call under {{@TypeChecked}} and 
{{@CompileStatic}}, as javac does. A call written in the declaring class itself 
({{new Sub().im()}} inside {{Base}}) works in all three modes today and should 
keep working, and so should a call through a receiver typed as {{Base}}.

  was:
A private method is not inherited (JLS 8.2), so it cannot be called through a 
receiver whose type is a subclass:

{code:groovy}
class Outer {
    static class Base { private String im() { 'im' } }
    static class Sub extends Base {}

    @groovy.transform.TypeChecked static tc() { new Sub().im() }
    @groovy.transform.CompileStatic static cs() { new Sub().im() }
    static dyn() { new Sub().im() }
}
{code}

* {{Outer.dyn()}} throws {{MissingMethodException}}: "No signature of method: 
im for class: Outer$Sub is applicable for argument types: ()"
* {{Outer.tc()}} compiles, then throws the same {{MissingMethodException}}
* {{Outer.cs()}} compiles and calls {{Base.im()}} directly
* javac rejects the equivalent Java: "cannot find symbol, symbol: method im(), 
location: class Sub"

The type checker should reject the call under {{@TypeChecked}} and 
{{@CompileStatic}}, as javac does. A call written in the declaring class itself 
({{new Sub().im()}} inside {{Base}}) works in all three modes today and should 
keep working, and so should a call through a receiver typed as {{Base}}.

PR: https://github.com/apache/groovy/pull/3044


> STC accepts a private method of a superclass called through a subclass 
> receiver
> -------------------------------------------------------------------------------
>
>                 Key: GROOVY-12510
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12510
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> A private method is not inherited (JLS 8.2), so it cannot be called through a 
> receiver whose type is a subclass:
> {code:groovy}
> class Outer {
>     static class Base { private String im() { 'im' } }
>     static class Sub extends Base {}
>     @groovy.transform.TypeChecked static tc() { new Sub().im() }
>     @groovy.transform.CompileStatic static cs() { new Sub().im() }
>     static dyn() { new Sub().im() }
> }
> {code}
> * {{Outer.dyn()}} throws {{MissingMethodException}}: "No signature of method: 
> im for class: Outer$Sub is applicable for argument types: ()"
> * {{Outer.tc()}} compiles, then throws the same {{MissingMethodException}}
> * {{Outer.cs()}} compiles and calls {{Base.im()}} directly
> * javac rejects the equivalent Java: "cannot find symbol, symbol: method 
> im(), location: class Sub"
> The type checker should reject the call under {{@TypeChecked}} and 
> {{@CompileStatic}}, as javac does. A call written in the declaring class 
> itself ({{new Sub().im()}} inside {{Base}}) works in all three modes today 
> and should keep working, and so should a call through a receiver typed as 
> {{Base}}.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to