Bug 560145 - [13] Improve error message for parse error on yield() method call
Summary: [13] Improve error message for parse error on yield() method call
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.14   Edit
Hardware: PC Windows 10
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2020-02-14 06:19 EST by Roman Guliak CLA
Modified: 2021-02-10 08:26 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roman Guliak CLA 2020-02-14 06:19:06 EST
Example:
public class Test1 extends Thread {
    public void run() {
        super.run();
        yield();
        System.out.println("Hello...");
    }
}

Parser fails to handle this case. Error is reported on the line containing yield():
Syntax error on token "(", Expression expected after this token

Also, all statements following this method call are just skipped, they are not presented in AST, only super.run() call is present.

Expected behavior:
yield() call and all following statements should be added to AST.
Comment 1 Andrey Loskutov CLA 2020-02-14 10:36:34 EST
I can't reproduce on 4.12 / 4.15 head of today with both Java 8 / 11 libraries. Which Eclipse / JDK version are you using?
Comment 2 Roman Guliak CLA 2020-02-14 12:43:14 EST
I use org.eclipse.jdt.core-3.20.0.jar.
Probably, it's 4.14.
"level" is set to AST.JLS13, "compliance" is JavaCore.VERSION_13, preview features for Java 13 are enabled.
Comment 3 Stephan Herrmann CLA 2020-02-15 07:38:05 EST
For comparison:

javac version 13:

$ javac --release 13 --enable-preview Test1.java 
Test1.java:4: error: invalid use of a restricted identifier 'yield'
        yield();
        ^
  (to invoke a method called yield, qualify the yield with a receiver or type name)
1 error


ecj (latest):

$ ecj --release 13 --enable-preview Test1.java 
----------
1. ERROR in /tmp/Test1.java (at line 4)
        yield();
             ^
Syntax error on token "(", Expression expected after this token
----------
1 problem (1 error)


If you change the call to "Thread.yield()" both compilers accept.

Ergo: in whether or not a program is legal, both compilers agree. Just ecj's error message isn't very helpful in this particular situation.
Comment 4 Stephan Herrmann CLA 2020-02-15 07:38:55 EST
tentatively putting this on the radar - no promise yet.
Comment 5 Roman Guliak CLA 2020-02-17 03:47:22 EST
The worst thing in this case is that code that follows yield() is just skipped.
I thought that when parser encounters other syntax errors it tries to recover somehow from them.
For example, when a statement is missing a semicolon, an error is reported, but statements that follow the error are still present in AST.

Is something similar possible in this case also?
Comment 6 Manoj N Palat CLA 2020-05-14 08:09:12 EDT
Bulk move out of 4.16
Comment 7 Manoj N Palat CLA 2020-08-15 14:03:15 EDT
keeping in the radar for 4.18
Comment 8 Manoj N Palat CLA 2021-02-10 08:26:54 EST
bulk move out of 4.19 - retarget once an owner is assigned