Community
Participate
Working Groups
public interface Foo { int run(int s1, int s2); } interface X { static Foo f = (int s5, int s6) -> x<ctrl-space> static int x1 = 2; } x1 should have been suggested in assist; but not happening that way. Thanks Anirban
(In reply to comment #0) > x1 should have been suggested in assist; but not happening that way. x1 should not be suggested there. It would lead it to a compile error: "Cannot reference a field before it is defined"
(In reply to comment #1) > (In reply to comment #0) > > > x1 should have been suggested in assist; but not happening that way. > > x1 should not be suggested there. It would lead it to a compile error: > "Cannot reference a field before it is defined" Hello Srikanth, Thanks for the comment. I thought, though, that all the members of an interface are at the 'same level'; i.e, the inherent sequentiality that is there in a method body, is not present here, and hence the sequentiality that is considered while suggesting in a metod body, should be done away with here. E.g, the following program compiles just fine: public interface Foo { int run(int s1, int s2); } interface X { static Foo f = (int x5, int x2) -> x1; static int x1 = 2; } Thanks Anirban
(In reply to comment #2) > E.g, the following program compiles just fine: > > public interface Foo { > int run(int s1, int s2); > } > > interface X { > > > static Foo f = (int x5, int x2) -> x1; > static int x1 = 2; > } Should it compile fine ? The following generates two errors with both eclipse and javac 8b81. interface Foo { int run(int s1, int s2); } interface X { static Foo f = foo(x1); static int x = x1; static int x1 = 2; static Foo foo(int x) { return null; } } The snippet you have posted compiles fine with eclipse, but crashes 8b81.
(In reply to comment #3) > Should it compile fine ? I think this is a bug in the eclipse compiler that it compiles this code with an illegal forward reference. Bug may be in org.eclipse.jdt.internal.compiler.ast.SingleNameReference.checkFieldAccess(BlockScope). Please open a fresh bug against the compiler with the test case from comment#2. Also note that solely relying on eclipse compiler behavior even as it being developed to make judgments about the language will be a mistake. We also have to take into account the spec and the reference compiler. Also relying on one's intuition (the argument in comment#2 about the "same level") can lead to trouble.
Please follow up on the potential compiler bug alluded to in comment#4
Hello, It seems both eclipse compiler and javac compiles the following code silently. public interface Foo { int run(int s1, int s2); } interface X { static Foo f = (int x5, int x2) -> x1; static int x1 = 2; } Invalidating the current bug, and filing a new bug for this (for records). Thanks Anirban
> Invalidating the current bug, and filing a new bug for this (for records). Not raising a compiler bug just now. Will raise later, if needed.
I found a scenario and raised a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=421926. As to whether the present bug itself: It is not truly invalid. We should offer the completion proposal if it is not indeed a true forward reference. i.e, we should offer proposals for subsequent static members iff such proposals would not in fact lead to compile errors. This could be a bit tricky.
Anirban, My bad. I apologize for the going back and forth and incorrect advice in between. It happens sometimes with corner cases :)
(In reply to Srikanth Sankaran from comment #9) > Anirban, My bad. I apologize for the going back and forth and incorrect > advice in > between. It happens sometimes with corner cases :) No problem at all. I'll fix the bug.
Created attachment 237977 [details] Patch Parent attached.
Assist node parent attached.
Thanks for the patch Anirban. I picked up the tests - the issue was already fixed by my patch for elided parameter support. http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=5ef6e5922904c18fe755d75c8b62a6c8d0b08d67 Please note: There is a new home for assist tests specific to Java8: CompletionParserTests18.java CompletionTests18.java ResolveTests18.java RunOnlyAssistTests18.java. BTW, what is testBug405125b testing exactly ?