Bug 574979 - [content assist] type reference not offered inside if with subsequent cast
Summary: [content assist] type reference not offered inside if with subsequent cast
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.21 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact: Vikas Chandra CLA
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks: 574913
  Show dependency tree
 
Reported: 2021-07-22 12:06 EDT by Stephan Herrmann CLA
Modified: 2021-08-07 10:10 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2021-07-22 12:06:48 EDT
Given
//---
public class Bug {
	void test (Object o) {
		if (true) {
			Str
			((String) o).toCharArray();
		}
	}
}
//---

here Str cannot be completed to String, nor any type (B -> Bug).

This doesn't happen when either the subsequent invocation or the enclosing if is removed.

This was discovered in bug 574823, where removing one check in CompletionParser.fetchNextToken() accidentally fixed this issue: remove 
   && this.expressionPtr <= -1
Comment 1 Andrey Loskutov CLA 2021-07-24 06:04:38 EDT
Still in I20210723-1800
Comment 2 Stephan Herrmann CLA 2021-07-24 06:43:32 EDT
(In reply to Andrey Loskutov from comment #1)
> Still in I20210723-1800

sure :)
Comment 3 Andrey Loskutov CLA 2021-07-24 06:52:36 EDT
(In reply to Stephan Herrmann from comment #2)
> (In reply to Andrey Loskutov from comment #1)
> > Still in I20210723-1800
> 
> sure :)

That was just a note fore me, because I've went over and validated all opened content assist bugs to see if some were fixed by latest changes. Some was, but not all :-)
Comment 4 Stephan Herrmann CLA 2021-08-05 13:34:39 EDT
Recovered AST:

//---
public class Bug {
  public Bug() {
  }
  void test(Object o) {
    if (true)
        {
          <CompleteOnMessageSendName:Str()>.toCharArray();
        }
  }
}
//---

Given that the CompletionOnMessageSendName actually has an argument "(String) o" (which just doesn't show in toString(), that AST is actually correct, though not totally desirable.
Comment 5 Stephan Herrmann CLA 2021-08-05 13:47:50 EDT
The fix for bug 574704 handled the situation in general, but forgot about types as the start of a statement.
Comment 6 Eclipse Genie CLA 2021-08-05 14:10:28 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183744
Comment 8 Stephan Herrmann CLA 2021-08-05 15:33:58 EDT
(In reply to Eclipse Genie from comment #7)
> Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183744 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=82df0cc7b95ecddb43047392b3f4b9e62defed0e

Released to master for 4.21 M3
Comment 9 Andrey Loskutov CLA 2021-08-07 10:10:42 EDT
Verified in I20210806-1800