Bug 405780 - [1.8][compiler] Bad syntax error 'insert ":: IdentifierOrNew"' for missing semicolon
Summary: [1.8][compiler] Bad syntax error 'insert ":: IdentifierOrNew"' for missing se...
Status: NEW
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: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-16 07:08 EDT by Markus Keller CLA
Modified: 2023-02-09 00:30 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2013-04-16 07:08:53 EDT
JDT UI's org.eclipse.jdt.ui.tests.refactoring.ExtractConstantTests#test34() fails in BETA_JAVA8 because we get an unexpected second syntax error when trying to compile the result of the refactoring.

Source:

package p;
import java.util.List;
class A {
	private static final String STRING = new String();

	{
		Object o= STRING;
		Object o2= STRING
	}
}

In master, we get the error:
- Syntax error, insert ";" to complete LocalVariableDeclarationStatement

In BETA_JAVA8, we get:
- Syntax error, insert ":: IdentifierOrNew" to complete Expression
- Syntax error, insert ";" to complete LocalVariableDeclarationStatement

The first error should not be issued. It doesn't make sense at all in pre-JLS8 ASTs, and even in JLS8, inserting a method reference would not fix the problem.
Comment 1 Srikanth Sankaran CLA 2013-04-30 02:50:36 EDT
(In reply to comment #0)

> In BETA_JAVA8, we get:
> - Syntax error, insert ":: IdentifierOrNew" to complete Expression
> - Syntax error, insert ";" to complete LocalVariableDeclarationStatement
> 
> The first error should not be issued. It doesn't make sense at all in
> pre-JLS8 ASTs, and even in JLS8, inserting a method reference would not fix
> the problem.

The parser is attempting to repair the broken program from purely
a grammatical pov.

Object o2 = STTRING::Identifer or 
Object o2 = STTRING::new

is a valid suggestion - if you ignore semantics and look only at syntax.
It is too much to ask the DiagnoseParser to know more about the language.

It is strange that this would show up in a 1.7 compliance settings also.
The grammar file does tag the relevant rules as being 1.8 specific, this
could be a bug in the parser generator.
Comment 2 Dani Megert CLA 2014-01-30 03:53:56 EST
If we don't get a fix we should disable the test for now in the BETA_JAVA8 branch.
Comment 3 Markus Keller CLA 2014-02-20 12:07:03 EST
(In reply to Srikanth Sankaran from comment #1)
> The parser is attempting to repair the broken program from purely
> a grammatical pov.
> 
> Object o2 = STRING::Identifier or 
> Object o2 = STRING::new
> 
> is a valid suggestion - if you ignore semantics and look only at syntax.
> It is too much to ask the DiagnoseParser to know more about the language.

Nope, these suggestions would not yield a syntactically valid statement. They are just as incomplete as the original 'Object o2= STRING', and they they won't ever reduce the syntax error count.

By the same argument, the DiagnoseParser could also tell me to replace 'Object' with 'ParameterizedType<Arg>' -- equally useless. The 'insert ";"' error resolves the syntax problem, so this one is also better (and enough) from a purely syntactical point of view.

Disabled failing JDT UI test with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=9ada4158cd9688430dee9ca16b78fe7d575af05a
Comment 4 Srikanth Sankaran CLA 2014-02-20 19:18:36 EST
(In reply to Markus Keller from comment #3)
> (In reply to Srikanth Sankaran from comment #1)
> > The parser is attempting to repair the broken program from purely
> > a grammatical pov.
> > 
> > Object o2 = STRING::Identifier or 
> > Object o2 = STRING::new
> > 
> > is a valid suggestion - if you ignore semantics and look only at syntax.
> > It is too much to ask the DiagnoseParser to know more about the language.
> 
> Nope, these suggestions would not yield a syntactically valid statement.
> They are just as incomplete as the original 'Object o2= STRING', and they
> they won't ever reduce the syntax error count.
> 
> By the same argument, the DiagnoseParser could also tell me to replace
> 'Object' with 'ParameterizedType<Arg>' -- equally useless. The 'insert ";"'
> error resolves the syntax problem, so this one is also better (and enough)
> from a purely syntactical point of view.

Mind you, there are two two recommendations and they together make a valid 
statement. It is not disputed that the old message is way better and enough.
Comment 5 Srikanth Sankaran CLA 2014-04-15 06:13:15 EDT
Given my time off plans and what is already on my plate, I don't expect to
get to this by 4.4
Comment 6 Manoj N Palat CLA 2016-04-20 23:45:04 EDT
sasi: can you please take a look at this for 4.7?
Comment 7 Manoj N Palat CLA 2018-05-16 01:30:20 EDT
Bulk move out of 4.8
Comment 8 Eclipse Genie CLA 2020-08-10 14:22:41 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 9 Eclipse Genie CLA 2023-02-09 00:30:30 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.