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

Eric Milles commented on GROOVY-8859:
-------------------------------------

Option 2 is implemented by 
https://github.com/apache/groovy/commit/032ed6c5082f7e45ac4e7dfb6d3e578b61f5956d

" && !methodNode.isPrivate() // GROOVY-7213, GROOVY-8859" can be removed from 
line 130 of {{TraitComposer}} to provide Option 1.

> traits allow access to private fields and static methods but not instance 
> methods
> ---------------------------------------------------------------------------------
>
>                 Key: GROOVY-8859
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8859
>             Project: Groovy
>          Issue Type: Question
>          Components: Compiler
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Minor
>              Labels: trait, traits
>
> It seems that private in a trait is akin to protected in a class.  For 
> example a class that implements a trait may access private fields (through 
> namespace syntax) and properties and call private static methods.  And it may 
> use Type.super.method() to disambiguate methods if necessary.  *Why, however, 
> can a class that implements a trait not call private instance methods?*  This 
> is not really covered in the language specification.
> {code:groovy}
> trait T {
>     private void privit() {
>         println 'private'
>     }
>     public void publik() {
>         println 'public'
>     }
> }
> class C implements T {
>     def m() {
>         publik()
>         privit()
>     }
> }
> new C().m()
> {code}
> This fails with missing method.  But if static modifier is added to privit, 
> it succeeds.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to