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 2020/07/17 04:28:00 UTC

[jira] [Commented] (GROOVY-5852) Static import on demand resolves capitalised reference

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

Paul King commented on GROOVY-5852:
-----------------------------------

I am not sure we went the right way here making them both fail. As per GROOVY-9618, for the property {{Pi}}, though not following recommended conventions, is allowed by the JavaBeans spec and would have a getter called {{getPi}}. For the case when we are compiling a Groovy class in the same module and happen to be able to peak at its defined properties, we could be "smarter" and rule out some options. But I'd suggest we don't try to be smart here and instead follow the same rules between Java and Groovy classes and for Groovy between classes in the same module and pre-compiled ones.

I won't reopen this issue but instead outline revisions to our behavior in GROOVY-9618. It isn't nice to alter our behavior back and forth but it is after all a somewhat rare edge case we are taking about.

> Static import on demand resolves capitalised reference
> ------------------------------------------------------
>
>                 Key: GROOVY-5852
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5852
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: Compiler
>            Reporter: Maxim Medvedev
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 2.5.6, 3.0.0-beta-1
>
>
> get a class 
> {code}
> class Constants {
>   static final pi = 3.14  //final property with implicit getter
> }
> {code}
> and another one
> {code}
> import static Constants.*
> println Pi  // first reference
> println Constants.Pi //second reference
> {code}
> IMHO both references to pi should throw a MissingPropertyException as they have capitalised first letter. Or both of them should not. Now first reference works while the second ref does not.
> BTW if we provide explicit 'public' modifier to pi, both references fail.



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