[jira] [Commented] (GROOVY-9779) Inconsistency with callable properties in static context

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-9779) Inconsistency with callable properties in static context

Eric Milles (Jira)

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

Daniil Ovchinnikov commented on GROOVY-9779:
--------------------------------------------

In @CS it fails to compile in all 3 cases.

I'd actually expect the static case ({{Container.staticC()}}) to fail as well. There is a reason why properties are callable, AFAIU in the early times it was common to define a property with Closure type instead of a method. If the instance case ({{container.instanceC()}}) will work, then what should happen here?
{code:groovy}
class Callable {
    def call() {
        42
    }
}

class C {
    def call = new Callable()
}

class Container {
    def c = new C()
}

def container = new Container()
container.c() // ?
// try container.c()
// then try container.c.call() as if it was written explicitly
// which in turn should try container.c.call.call()
// which in turn should try container.c.call.call.call()
// ...
{code}

> Inconsistency with callable properties in static context
> --------------------------------------------------------
>
>                 Key: GROOVY-9779
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9779
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.6
>            Reporter: Daniil Ovchinnikov
>            Assignee: Eric Milles
>            Priority: Major
>
> {code:title=playground.groovy}
> class C {
>     def call() {
>         42
>     }
> }
> class Container {
>     static final staticC   = new C()
>     def          instanceC = new C()
> }
> assert Container.staticC() == 42 // works fine
> def container = new Container()
> assert container.staticC() == 42 // MissingMethodException
> assert container.instanceC() == 42 // MissingMethodException
> {code}
> I'd expect the invocations to fail or to work in both static and instance contexts.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)