[
https://issues.apache.org/jira/browse/GROOVY-7024?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-7024:
------------------------------
Description:
I have a class with the following code:
{code}
class UnitGroupMap {
...
static Map suffixPriority = ['a' : 10, 'b' : 20]
...
enum UnitGroup {
SAMPLE("foo"),
...
UnitGroup(String name) {
...
suffixPriority[name] = priority
...
}
...
}
...
}
{code}
The compiler does not complain, STS doesn't complain, but at runtime, there's
an exception that "suffixPriority" is not a member of UnitGroupMap.UnitGroup.
To make this code work, I have to precede the suffixPriority reference with the
class name: UnitGroupMap.suffixPriority
Either this should work as written, or the compiler should generate an error or
at least a warning. However, STS at least highlights suffixPriority in italics
as though it can and does see the field should be coming from the parent class,
UnitGroupMap.
was:
I have a class with the following code:
class UnitGroupMap {
...
static Map suffixPriority = ['a' : 10, 'b' : 20]
...
enum UnitGroup {
SAMPLE("foo"),
...
UnitGroup(String name) {
...
suffixPriority[name] = priority
...
}
...
}
...
}
The compiler does not complain, STS doesn't complain, but at runtime, there's
an exception that "suffixPriority" is not a member of UnitGroupMap.UnitGroup.
To make this code work, I have to precede the suffixPriority reference with the
class name: UnitGroupMap.suffixPriority
Either this should work as written, or the compiler should generate an error or
at least a warning. However, STS at least highlights suffixPriority in italics
as though it can and does see the field should be coming from the parent class,
UnitGroupMap.
> Reference to static member of parent class in enum constructor fails at
> runtime
> -------------------------------------------------------------------------------
>
> Key: GROOVY-7024
> URL: https://issues.apache.org/jira/browse/GROOVY-7024
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 2.3.0
> Environment: Mac OS X running STS in a Grails context
> Reporter: Mitsu Hadeishi
> Priority: Minor
> Labels: inner, scope
>
> I have a class with the following code:
> {code}
> class UnitGroupMap {
> ...
> static Map suffixPriority = ['a' : 10, 'b' : 20]
> ...
> enum UnitGroup {
> SAMPLE("foo"),
> ...
> UnitGroup(String name) {
> ...
> suffixPriority[name] = priority
> ...
> }
> ...
> }
> ...
> }
> {code}
> The compiler does not complain, STS doesn't complain, but at runtime, there's
> an exception that "suffixPriority" is not a member of UnitGroupMap.UnitGroup.
> To make this code work, I have to precede the suffixPriority reference with
> the class name: UnitGroupMap.suffixPriority
> Either this should work as written, or the compiler should generate an error
> or at least a warning. However, STS at least highlights suffixPriority in
> italics as though it can and does see the field should be coming from the
> parent class, UnitGroupMap.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)