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

Paul King commented on GROOVY-10433:
------------------------------------

Groovy is a little more nuanced than Java.

Groovy allows keywords to be used for named parameters and map keys, e.g.:
{code}
var var = [def: 1, as: 2, in: 3, trait: 4,
           private: 5, public: 6, class: 7,
           trait: 8, protected: 9, sealed: 10,
           permits: 11, interface: 12, implements: 13,
           extends: 14, it: 15, this: 16, super: 17]
{code}

Groovy has a similar concept to "restricted identifier". Currently only "var", 
"in", "trait", "as", "yield", "permits", and "record" are in this list.
These can be used for variable/field declarations and method names. Method 
calls to these names must be qualified with "this." otherwise a "Modifiers or 
return type is required" occurs during parsing. I don't know if it is possible 
to remove this last error somehow. We should check whether "sealed" can be in 
this list. (The purpose of this issue.) We also have "def" excluded from this 
list, I presume for some known issue.

Groovy also allows the remaining keywords to be used as method names when 
quoted and prefixed with "this." when calling, like the previous "private" 
example and another, e.g.:
{code}
def "assert"() { false }
this.assert()
{code}
For these keywords, there is normally a corresponding "Unexpected input" error 
message during parsing if the "this." qualifier is left out. Strangely, for 
this last example, "assert", it has a slightly different error message: 
Unexpected input: '<EOF>' but possibly that is okay.

As to the "{ non, sealed -> return non-sealed }" example, I think will be fixed 
if we can make "sealed" a restricted identifier.



> "sealed" not usable as a restricted identifier
> ----------------------------------------------
>
>                 Key: GROOVY-10433
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10433
>             Project: Groovy
>          Issue Type: Bug
>          Components: parser-antlr4
>    Affects Versions: 4.0.0-rc-2
>            Reporter: Eric Milles
>            Priority: Major
>
> The restricted identifier "sealed" is not usable for a variable or member 
> name any longer.
> {code:groovy}
> def sealed = false // fails to parse
> def record = false // okay
> def permits = false // okay
> class C {
>   def sealed = false // fails to parse
>   def record = false // okay
>   def permits = false // okay
> }
> {code}
> And this should still work as minus: "\{ non, sealed -> return non-sealed \}"



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

Reply via email to