You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/12/19 19:21:00 UTC

[jira] [Commented] (GROOVY-7859) Erroneous method pointer expressions pass STC

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

Eric Milles commented on GROOVY-7859:
-------------------------------------

Is the expectation that STC know that "x" requires 1 argument when initialized from "String.&length" or "String.&size"?  "x" is callable if a string argument is supplied.

> Erroneous method pointer expressions pass STC
> ---------------------------------------------
>
>                 Key: GROOVY-7859
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7859
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.7
>            Reporter: Shil Sinha
>            Assignee: Shil Sinha
>            Priority: Major
>
> Method pointer expressions are not type checked (with STC enabled). The following example should not compile for a number of reasons:
> {code}
> @groovy.transform.TypeChecked
> void test() {
>   def x = 'abc'.&bar //bar is not a String method
>   x() // groovy.lang.MissingMethodException
>   x = String.&length //length is a non-static method
>   x() // java.lang.IllegalArgumentException: object is not an instance of declaring class
>   x = String.&size //size is a non-static extension method
>   x() // java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
> }
> test()
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)