You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/08/06 10:13:00 UTC
[jira] [Resolved] (GROOVY-7891) Possible Problem With Closures
Calling Private Methods In A Trait
[ https://issues.apache.org/jira/browse/GROOVY-7891?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King resolved GROOVY-7891.
-------------------------------
Resolution: Duplicate
Assignee: Paul King
I presume this is a duplicate of GROOVY-7797. Certainly this code works now:
{code}
/*
class C implements B {
@Override
void doSomething() {
B.super.doSomething()
}
static void main(String[] args) {
new C().doSomething()
}
}
trait A {
void doSomething() {
println "A"
}
}
trait B extends A {}
*/
class Demo implements SomeTrait {
static void main(args) {
assert new Demo().somePublicMethod() == 42
}
}
trait SomeTrait {
int somePublicMethod() {
def someClosure = {
somePrivateMethod()
}
someClosure()
}
private int somePrivateMethod() { 42 }
}
{code}
> Possible Problem With Closures Calling Private Methods In A Trait
> -----------------------------------------------------------------
>
> Key: GROOVY-7891
> URL: https://issues.apache.org/jira/browse/GROOVY-7891
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.4.5
> Reporter: Jeff Scott Brown
> Assignee: Paul King
> Priority: Major
>
> It looks like a closure defined in a trait does not have access to private methods defined in the trait. I am not sure if this is broken or not.
> {code}
> trait SomeTrait {
> void somePublicMethod() {
> def someClosure = {
> somePrivateMethod()
> }
> someClosure()
> }
> private void somePrivateMethod() {}
> }
> {code}
> {code}
> class Demo implements SomeTrait {
> static void main(args) {
> new Demo().somePublicMethod()
> }
> }
> {code}
> {code}
> $ groovy Demo
> Caught: groovy.lang.MissingMethodException: No signature of method: Demo.somePrivateMethod() is applicable for argument types: (Demo) values: [Demo@2473d930]
> groovy.lang.MissingMethodException: No signature of method: Demo.somePrivateMethod() is applicable for argument types: (Demo) values: [Demo@2473d930]
> at SomeTrait$Trait$Helper$_somePublicMethod_closure1.doCall(SomeTrait.groovy:5)
> at SomeTrait$Trait$Helper$_somePublicMethod_closure1.doCall(SomeTrait.groovy)
> at SomeTrait$Trait$Helper.somePublicMethod(SomeTrait.groovy:7)
> at SomeTrait$Trait$Helper$somePublicMethod.call(Unknown Source)
> at Demo.somePublicMethod(Demo.groovy)
> at SomeTrait$somePublicMethod.call(Unknown Source)
> at Demo.main(Demo.groovy:3)
> {code}
> Please advise. Thanks for the input.
> https://github.com/grails/grails-core/issues/10060
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)