Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 405125 - [1.8][code assist] static members of an interface appearing after the declaration of a static member lambda expression are not being suggested.
Summary: [1.8][code assist] static members of an interface appearing after the declara...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: ANIRBAN CHAKRABORTY CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 402079
  Show dependency tree
 
Reported: 2013-04-08 01:30 EDT by ANIRBAN CHAKRABORTY CLA
Modified: 2013-12-13 06:11 EST (History)
1 user (show)

See Also:


Attachments
Patch (5.32 KB, patch)
2013-12-03 15:53 EST, ANIRBAN CHAKRABORTY CLA
anchakrk: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ANIRBAN CHAKRABORTY CLA 2013-04-08 01:30:56 EDT
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
Comment 1 Srikanth Sankaran CLA 2013-04-08 01:39:16 EDT
(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"
Comment 2 ANIRBAN CHAKRABORTY CLA 2013-04-08 01:57:22 EDT
(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
Comment 3 Srikanth Sankaran CLA 2013-04-08 02:11:29 EDT
(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.
Comment 4 Srikanth Sankaran CLA 2013-04-08 02:22:39 EDT
(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.
Comment 5 Srikanth Sankaran CLA 2013-11-11 00:13:57 EST
Please follow up on the potential compiler bug alluded to in comment#4
Comment 6 ANIRBAN CHAKRABORTY CLA 2013-11-17 22:31:01 EST
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
Comment 7 ANIRBAN CHAKRABORTY CLA 2013-11-17 22:36:06 EST
 
> 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.
Comment 8 Srikanth Sankaran CLA 2013-11-17 22:46:20 EST
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.
Comment 9 Srikanth Sankaran CLA 2013-11-17 22:49:04 EST
Anirban, My bad. I apologize for the going back and forth and incorrect advice in
between. It happens sometimes with corner cases :)
Comment 10 ANIRBAN CHAKRABORTY CLA 2013-11-17 23:21:47 EST
(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.
Comment 11 ANIRBAN CHAKRABORTY CLA 2013-12-03 15:53:44 EST
Created attachment 237977 [details]
Patch

Parent attached.
Comment 12 ANIRBAN CHAKRABORTY CLA 2013-12-03 15:55:05 EST
Assist node parent attached.
Comment 13 Srikanth Sankaran CLA 2013-12-13 06:11:50 EST
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 ?