You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (JIRA)" <ji...@apache.org> on 2019/05/23 23:59:00 UTC

[jira] [Commented] (GROOVY-9140) Class.&instanceMethod with incorrect first param

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

Daniel Sun commented on GROOVY-9140:
------------------------------------

After I think about the issue for a while, theĀ {{IllegalArgumentException}} is reasonable too, because {{m}} does exist but the expected arguments have not passed in(expecting an instance of {{Y}} as its first argument).
Maybe we could refine the error message and give more details to users.

> Class.&instanceMethod with incorrect first param
> ------------------------------------------------
>
>                 Key: GROOVY-9140
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9140
>             Project: Groovy
>          Issue Type: Dependency upgrade
>    Affects Versions: 3.0.0-beta-1
>            Reporter: Paul King
>            Priority: Major
>
> In Groovy 3 we extended the method pointer to also work for a Class receiver and instance method. When used in this way, the method closure produced accepts an additional initial argument being the instance receiver. This works when supplied with a correct argument but gives an {{IllegalArgumentException}} instead of {{MissingMethodException}} when an illegal argument is supplied. E.g.:
> {code}
> class Y {
>   def m() {1}
> }
> ref = Y.&m
> assert ref(new Y()) == 1
> assert ref() == 1 // => java.lang.IllegalArgumentException: object is not an instance of declaring class [Should just be missing method exception?]
> assert ref(1) == 1 // => java.lang.IllegalArgumentException: object is not an instance of declaring class [Should just be missing method exception?]
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)