[jira] [Commented] (GROOVY-8214) Implicit .call is inconsistent

2017-06-05 Thread Daniil Ovchinnikov (JIRA)

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

Daniil Ovchinnikov commented on GROOVY-8214:


All cases work when value returned from property is a {{Closure}}. In 
{{Closure}} cases explicit method takes precedence:
{code}
class A {
  def getFoo() { return { "closure" } }
  def foo() { "method" }
}
println new A().foo() // method
{code}

I see no reason not to allow the same behaviour for all objects with 
{{.call()}} defined.

There is special handling for closures in 
{{groovy.lang.MetaClassImpl#invokePropertyOrMissing}}. In may be replaced with 
something like this (pseudocode):
{code}
if (/*necessary checks*/) return invokeMethod(value, "call", args)
{code}

> Implicit .call is inconsistent
> --
>
> Key: GROOVY-8214
> URL: https://issues.apache.org/jira/browse/GROOVY-8214
> Project: Groovy
>  Issue Type: Bug
>Reporter: Daniil Ovchinnikov
>
> {code}
> interface Callable {
>   def call()
> }
> def callable = new Callable() {
>   def call() { println "callable local var" }
> }
> callable.call()
> callable()
> class ClassWithCallableField {
>   public ppp = new Callable() {
> def call() { println "callable field" }
>   }
> }
> def cwcp = new ClassWithCallableField()
> cwcp.ppp.call()
> cwcp.ppp() // MME
> def foo(Callable p) {
>   p.call()
>   p()
> }
> foo new Callable() {
>   def call() { println "callable parameter" }
> }
> class ClassWithCallableGetter {
>   def getGetter() {
> new Callable() {
>   def call() { println "callable getter" }
> }
>   }
> }
> def cwcg = new ClassWithCallableGetter()
> cwcg.getter.call()
> cwcg.getter() // MME
> class ClassWithCallableFieldInside {
>   public bbb = new Callable() {
> def call() { println "callable field inside class" }
>   }
>   def foo() {
> bbb.call()
> bbb()
>   }
> }
> new ClassWithCallableFieldInside().foo()
> class ClassWithCallableGetterInside {
>   def getGetter() {
> new Callable() {
>   def call() { println "callable getter inside class" }
> }
>   }
>   def foo() {
> getter.call()
> getter() // MME
>   }
> }
> new ClassWithCallableGetterInside().foo()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (GROOVY-8214) Implicit .call is inconsistent

2017-06-02 Thread Jochen Theodorou (JIRA)

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

Jochen Theodorou commented on GROOVY-8214:
--

the only consistent way to resolve this, would be to remove the feature for 
non-static Groovy. If you have foo.bar(), then you cannot easily know if the 
author did mean to do foo.bar.call() or if he did mean to call the method bar 
on foo. And the method as well as a callable property may exist at the same 
time. That is why this feature is limited to local variables only

> Implicit .call is inconsistent
> --
>
> Key: GROOVY-8214
> URL: https://issues.apache.org/jira/browse/GROOVY-8214
> Project: Groovy
>  Issue Type: Bug
>Reporter: Daniil Ovchinnikov
>
> {code}
> interface Callable {
>   def call()
> }
> def callable = new Callable() {
>   def call() { println "callable local var" }
> }
> callable.call()
> callable()
> class ClassWithCallableField {
>   public ppp = new Callable() {
> def call() { println "callable field" }
>   }
> }
> def cwcp = new ClassWithCallableField()
> cwcp.ppp.call()
> cwcp.ppp() // MME
> def foo(Callable p) {
>   p.call()
>   p()
> }
> foo new Callable() {
>   def call() { println "callable parameter" }
> }
> class ClassWithCallableGetter {
>   def getGetter() {
> new Callable() {
>   def call() { println "callable getter" }
> }
>   }
> }
> def cwcg = new ClassWithCallableGetter()
> cwcg.getter.call()
> cwcg.getter() // MME
> class ClassWithCallableFieldInside {
>   public bbb = new Callable() {
> def call() { println "callable field inside class" }
>   }
>   def foo() {
> bbb.call()
> bbb()
>   }
> }
> new ClassWithCallableFieldInside().foo()
> class ClassWithCallableGetterInside {
>   def getGetter() {
> new Callable() {
>   def call() { println "callable getter inside class" }
> }
>   }
>   def foo() {
> getter.call()
> getter() // MME
>   }
> }
> new ClassWithCallableGetterInside().foo()
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)