Community
Participate
Working Groups
Build Identifier: I20110127-2034 (3.7M5) public class Test { private class Bar {} private void foo() { new Bar(); } } compiler emits a warning (or an error depending on the compiler settings): The method foo() from the type Test can be declared as static However, adding a static qualifier produces a compiler error because no enclosing instance of type Test is accessible. Reproducible: Always Steps to Reproduce: Might be related to bug 335780 (although it is about a potential match and not a definitive one like this one).
Created attachment 188036 [details] proposed fix v1.0 + regression tests Allocation of a (non-static) member typewithout an enclosing instance of a parent type is done via AllocationExpression, while with an enclosing instance is done via QualifiedAllocationExpression. This patch adds a check in AllocationExpression#analyseCode(..) to reset the static flag for a method if an allocation expression is encountered for a non-static member type.
All tests pass. Satyam, please review. Thanks!
Ayush, The following test fails with the patch. public class SuperTest { class Bar {} } public class Test extends SuperTest{ private void foo() { new Bar(); } }
Created attachment 188147 [details] proposed fix v1.1 + regression tests Here's the updated fix. I was using the wrong bits - ASTNode.IsMemberType bits, whereas I should've used TagBits.IsMemberType, since i'm checking the binding bits and not the AST node bits. Added another test to take care of this.
+1. The patch looks good for me.
Released in HEAD for 3.7M6
Verified for 3.7M6.