[jira] [Commented] (GROOVY-8360) Enums that are nested classes do not have the static modifier set
[ https://issues.apache.org/jira/browse/GROOVY-8360?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16216167#comment-16216167 ] ASF GitHub Bot commented on GROOVY-8360: Github user shils commented on a diff in the pull request: https://github.com/apache/groovy/pull/619#discussion_r146433436 --- Diff: src/test/gls/enums/EnumTest.groovy --- @@ -592,6 +592,80 @@ class EnumTest extends CompilableTestSupport { assert UsState.ID.toString() == 'Idaho' ''' } + +void testNestedEnumHasStaticModifier_GROOVY_8360() { +assertScript ''' +class Foo { +enum Bar { +X('x'), Y +String s +Bar(String s) { this.s = s } +Bar() {} +} +} +assert java.lang.reflect.Modifier.isStatic(Foo.Bar.modifiers) +assert Foo.Bar.X.s == 'x' +''' +} + +void testEnumWithinInnerClassHasStaticModifier_GROOVY_8360() { +assertScript ''' +class Foo { +class Baz { +enum Bar { +X('x'), Y +String s +Bar(String s) { this.s = s } +Bar() {} +} +} +} +assert java.lang.reflect.Modifier.isStatic(Foo.Baz.Bar.modifiers) +assert Foo.Baz.Bar.X.s == 'x' +''' +} + +void testNestedEnumHasStaticModifierSC_GROOVY_8360() { +assertScript ''' +@groovy.transform.CompileStatic +class Foo { +enum Bar { +X('x'), Y +String s +Bar(String s) { this.s = s } +Bar() {} +} +} +@groovy.transform.CompileStatic +void test() { +assert java.lang.reflect.Modifier.isStatic(Foo.Bar.getModifiers()) --- End diff -- Unrelated to this issue - property style getter calls on Enum classes throw NoSuchFieldErrors at runtime when statically compiled. > Enums that are nested classes do not have the static modifier set > - > > Key: GROOVY-8360 > URL: https://issues.apache.org/jira/browse/GROOVY-8360 > Project: Groovy > Issue Type: Bug > Components: Compiler >Affects Versions: 3.x, 2.6.0-alpha-1, 2.4.12, 2.5.0-beta-2 >Reporter: Shil Sinha > > In java, enums that are nested classes have the static modifier set i.e. if > Bar is an enum defined within a class Foo, {{assert > Modifier.isStatic(Foo.Bar.modifiers)}} passes. The assertion does not hold if > Foo and Bar are defined in groovy: > {code} > class Foo { > enum Bar { > X > } > } > > assert java.lang.reflect.Modifier.isStatic(Foo.Bar.modifiers) > {code} > This can be problematic in cases like https://mongodb.github.io/morphia/, > where the type of a mapped field cannot be a non-static inner class. Of > course that library could also be more enum-aware when validating mapped > fields, but that's a separate issue. > A simple workaround for this issue is to explicitly declare the enum as > static, so it's not critical that a patch for this be in 2.4.X if it's > considered a breaking change (though no tests fail with the change.) -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[GitHub] groovy pull request #619: GROOVY-8360: Enums that are inner classes should h...
Github user shils commented on a diff in the pull request: https://github.com/apache/groovy/pull/619#discussion_r146433436 --- Diff: src/test/gls/enums/EnumTest.groovy --- @@ -592,6 +592,80 @@ class EnumTest extends CompilableTestSupport { assert UsState.ID.toString() == 'Idaho' ''' } + +void testNestedEnumHasStaticModifier_GROOVY_8360() { +assertScript ''' +class Foo { +enum Bar { +X('x'), Y +String s +Bar(String s) { this.s = s } +Bar() {} +} +} +assert java.lang.reflect.Modifier.isStatic(Foo.Bar.modifiers) +assert Foo.Bar.X.s == 'x' +''' +} + +void testEnumWithinInnerClassHasStaticModifier_GROOVY_8360() { +assertScript ''' +class Foo { +class Baz { +enum Bar { +X('x'), Y +String s +Bar(String s) { this.s = s } +Bar() {} +} +} +} +assert java.lang.reflect.Modifier.isStatic(Foo.Baz.Bar.modifiers) +assert Foo.Baz.Bar.X.s == 'x' +''' +} + +void testNestedEnumHasStaticModifierSC_GROOVY_8360() { +assertScript ''' +@groovy.transform.CompileStatic +class Foo { +enum Bar { +X('x'), Y +String s +Bar(String s) { this.s = s } +Bar() {} +} +} +@groovy.transform.CompileStatic +void test() { +assert java.lang.reflect.Modifier.isStatic(Foo.Bar.getModifiers()) --- End diff -- Unrelated to this issue - property style getter calls on Enum classes throw NoSuchFieldErrors at runtime when statically compiled. ---
[jira] [Commented] (GROOVY-8362) Nested class is resolved via another nested class with package name
[ https://issues.apache.org/jira/browse/GROOVY-8362?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16215789#comment-16215789 ] Daniil Ovchinnikov commented on GROOVY-8362: I can provide pull requests for issues opened by me if somebody could explain if this is really a bug or an undocumented feature. > Nested class is resolved via another nested class with package name > --- > > Key: GROOVY-8362 > URL: https://issues.apache.org/jira/browse/GROOVY-8362 > Project: Groovy > Issue Type: Bug >Reporter: Daniil Ovchinnikov >Priority: Critical > > {code:title=bugs/bugs.groovy} > package bugs > class Current { > static class bugs { > static class Target {} > } > static usage() { > new Target() // error expected > } > } > println Current.usage() // bugs.Current$bugs$Target@20d28811 > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (GROOVY-8363) Implementing List with a delegated data source results in StackOverflowException
[ https://issues.apache.org/jira/browse/GROOVY-8363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16215348#comment-16215348 ] Kevin Chen commented on GROOVY-8363: Ah, never mind, I see that you're right. I'm actually still on 2.4.7 for this project though and not sure I can use this solution :( > Implementing List with a delegated data source results in > StackOverflowException > > > Key: GROOVY-8363 > URL: https://issues.apache.org/jira/browse/GROOVY-8363 > Project: Groovy > Issue Type: Bug >Reporter: Kevin Chen > > Preface: not experienced with submitting bugs to the Groovy project, so > please bear with me if anything's unclear. > I'm getting a StackOverflowException from this bit of code (I think just > including this snippet demonstrates better than I can explain verbally): > {code:title=DelegateList.groovy|borderStyle=solid} > class DelegateList { > private List lowerCaseStrings = [] > private DelegatingListImplementation uppercaseStrings = new > DelegatingListImplementation() > private abstract static class DelegatingList implements List { > abstract List getDelegate() > @Override > int size() { > return delegate.size() > } > @Override > boolean isEmpty() { > return delegate.isEmpty() > } > // etc. > } > private class DelegatingListImplementation extends DelegatingList { > @Override > List getDelegate() { > return lowerCaseStrings.collect { it.toUpperCase() } > } > } > DelegateList(Collection strings) { > lowerCaseStrings = strings.toList().collect { it.toLowerCase() } > } > List getUppercase() { > return uppercaseStrings > } > public static void main(String[] args) { > def d = new DelegateList(['hello', 'bye']) > println d.getUppercase() // StackOverflowError > } > } > {code} > The equivalent doesn't happen in Java. Example repository with both runnables > is here: [https://github.com/aspin/groovy-delegate-list]. I'm not really sure > how to get deeper into the source of this (Groovy's closure resolving > strategies?) and/or how to work around. -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Updated] (GROOVY-8364) Nested class of parent Java class is not resolved
[ https://issues.apache.org/jira/browse/GROOVY-8364?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Daniil Ovchinnikov updated GROOVY-8364: --- Description: {code:title=bugs/A.java} package bugs; public class A { public interface Inner {} } {code} {code:title=bugs/B.java} package bugs; public class B { public interface Inner {} } {code} {code:title=bugs/test/test.groovy} package bugs.test import bugs.A //import static bugs.B.Inner class Current extends A { static usage() { return Inner // here } } println Current.usage() {code} {noformat} Apparent variable 'Inner' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'Inner' but left out brackets in a place not allowed by the grammar. @ line 8, column 12. return Inner ^ {noformat} Note the class could be resolved only via import. Now try to uncomment a static import. While usually the nested class takes precedence over an import, in this case the failure to resolve a nested class results in a silent resolution to {{bugs.B.Inner}}, i.e. no error is reported. In both cases the reference is expected to be resolved to {{bugs.A.Inner}} was: {code:title=bugs/A.java} package bugs; public class A { public interface Inner {} } {code} {code:title=bugs/B.java} package bugs; public class B { public interface Inner {} } {code} {code:title=bugs/test/test.groovy} package bugs.test import bugs.A //import static bugs.B.Inner class Current extends A { static usage() { return Inner // here } } println Current.usage() {code} {noformat} Apparent variable 'Inner' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'Inner' but left out brackets in a place not allowed by the grammar. @ line 8, column 12. return Inner ^ {noformat} Note the class could be resolved only via import. Now try to uncomment a static import. While usually the nested class takes precedence over an import, in this case the failure to resolve a nested class results in a silent resolution to {{bugs.B.Inner}}, i.e. no error is reported. > Nested class of parent Java class is not resolved > - > > Key: GROOVY-8364 > URL: https://issues.apache.org/jira/browse/GROOVY-8364 > Project: Groovy > Issue Type: Bug >Reporter: Daniil Ovchinnikov > > {code:title=bugs/A.java} > package bugs; > public class A { > public interface Inner {} > } > {code} > {code:title=bugs/B.java} > package bugs; > public class B { > public interface Inner {} > } > {code} > {code:title=bugs/test/test.groovy} > package bugs.test > import bugs.A > //import static bugs.B.Inner > class Current extends A { > static usage() { > return Inner // here > } > } > println Current.usage() > {code} > {noformat} > Apparent variable 'Inner' was found in a static scope but doesn't refer to a > local variable, static field or class. Possible causes: > You attempted to reference a variable in the binding or an instance variable > from a static context. > You misspelled a classname or statically imported field. Please check the > spelling. > You attempted to use a method 'Inner' but left out brackets in a place not > allowed by the grammar. > @ line 8, column 12. >return Inner > ^ > {noformat} > Note the class could be resolved only via import. > Now try to uncomment a static import. > While usually the nested class takes precedence over an import, in this case > the failure to resolve a nested class results in a silent resolution to > {{bugs.B.Inner}}, i.e. no error is reported. > In both cases the reference is expected to be resolved to {{bugs.A.Inner}} -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Created] (GROOVY-8364) Nested class of parent Java class is not resolved
Daniil Ovchinnikov created GROOVY-8364: -- Summary: Nested class of parent Java class is not resolved Key: GROOVY-8364 URL: https://issues.apache.org/jira/browse/GROOVY-8364 Project: Groovy Issue Type: Bug Reporter: Daniil Ovchinnikov {code:title=bugs/A.java} package bugs; public class A { public interface Inner {} } {code} {code:title=bugs/B.java} package bugs; public class B { public interface Inner {} } {code} {code:title=bugs/test/test.groovy} package bugs.test import bugs.A //import static bugs.B.Inner class Current extends A { static usage() { return Inner // here } } println Current.usage() {code} {noformat} Apparent variable 'Inner' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'Inner' but left out brackets in a place not allowed by the grammar. @ line 8, column 12. return Inner ^ {noformat} Note the class could be resolved only via import. Now try to uncomment a static import. While usually the nested class takes precedence over an import, in this case the failure to resolve a nested class results in a silent resolution to {{bugs.B.Inner}}, i.e. no error is reported. -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (GROOVY-8363) Implementing List with a delegated data source results in StackOverflowException
[ https://issues.apache.org/jira/browse/GROOVY-8363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16215279#comment-16215279 ] Kevin Chen commented on GROOVY-8363: Why do you think the @CompileStatic annotation is the part that sidesteps the potential bug and not the @Delegate? (Actually, for that matter, why is @CompileStatic appropriate for the DelegatingListImplementation when DelegatingListImplementation relies on the surrounding outer class instance?). > Implementing List with a delegated data source results in > StackOverflowException > > > Key: GROOVY-8363 > URL: https://issues.apache.org/jira/browse/GROOVY-8363 > Project: Groovy > Issue Type: Bug >Reporter: Kevin Chen > > Preface: not experienced with submitting bugs to the Groovy project, so > please bear with me if anything's unclear. > I'm getting a StackOverflowException from this bit of code (I think just > including this snippet demonstrates better than I can explain verbally): > {code:title=DelegateList.groovy|borderStyle=solid} > class DelegateList { > private List lowerCaseStrings = [] > private DelegatingListImplementation uppercaseStrings = new > DelegatingListImplementation() > private abstract static class DelegatingList implements List { > abstract List getDelegate() > @Override > int size() { > return delegate.size() > } > @Override > boolean isEmpty() { > return delegate.isEmpty() > } > // etc. > } > private class DelegatingListImplementation extends DelegatingList { > @Override > List getDelegate() { > return lowerCaseStrings.collect { it.toUpperCase() } > } > } > DelegateList(Collection strings) { > lowerCaseStrings = strings.toList().collect { it.toLowerCase() } > } > List getUppercase() { > return uppercaseStrings > } > public static void main(String[] args) { > def d = new DelegateList(['hello', 'bye']) > println d.getUppercase() // StackOverflowError > } > } > {code} > The equivalent doesn't happen in Java. Example repository with both runnables > is here: [https://github.com/aspin/groovy-delegate-list]. I'm not really sure > how to get deeper into the source of this (Groovy's closure resolving > strategies?) and/or how to work around. -- This message was sent by Atlassian JIRA (v6.4.14#64029)
[jira] [Commented] (GROOVY-8363) Implementing List with a delegated data source results in StackOverflowException
[ https://issues.apache.org/jira/browse/GROOVY-8363?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16215280#comment-16215280 ] Kevin Chen commented on GROOVY-8363: Just threw on the @CompileStatic annotation and it doesn't change anything with the original {{extends List}} implementation. > Implementing List with a delegated data source results in > StackOverflowException > > > Key: GROOVY-8363 > URL: https://issues.apache.org/jira/browse/GROOVY-8363 > Project: Groovy > Issue Type: Bug >Reporter: Kevin Chen > > Preface: not experienced with submitting bugs to the Groovy project, so > please bear with me if anything's unclear. > I'm getting a StackOverflowException from this bit of code (I think just > including this snippet demonstrates better than I can explain verbally): > {code:title=DelegateList.groovy|borderStyle=solid} > class DelegateList { > private List lowerCaseStrings = [] > private DelegatingListImplementation uppercaseStrings = new > DelegatingListImplementation() > private abstract static class DelegatingList implements List { > abstract List getDelegate() > @Override > int size() { > return delegate.size() > } > @Override > boolean isEmpty() { > return delegate.isEmpty() > } > // etc. > } > private class DelegatingListImplementation extends DelegatingList { > @Override > List getDelegate() { > return lowerCaseStrings.collect { it.toUpperCase() } > } > } > DelegateList(Collection strings) { > lowerCaseStrings = strings.toList().collect { it.toLowerCase() } > } > List getUppercase() { > return uppercaseStrings > } > public static void main(String[] args) { > def d = new DelegateList(['hello', 'bye']) > println d.getUppercase() // StackOverflowError > } > } > {code} > The equivalent doesn't happen in Java. Example repository with both runnables > is here: [https://github.com/aspin/groovy-delegate-list]. I'm not really sure > how to get deeper into the source of this (Groovy's closure resolving > strategies?) and/or how to work around. -- This message was sent by Atlassian JIRA (v6.4.14#64029)