Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23] ECJ rejects 'module' as top level package in an import statement #2607

Closed
jarthana opened this issue Jun 19, 2024 · 1 comment
Closed
Assignees
Milestone

Comments

@jarthana
Copy link
Member

Given the two classes as below:

package module;
public class Z {}

and

import module.Z; // Error here - Syntax error on token ".", delete this token
public class X {} 

However, we accept module.Z z = null;

The relevant spec that allows this:

During the reduction of input characters to input elements ([3.5](https://docs.oracle.com/javase/specs/jls/se22/html/jls-3.html#jls-3.5)), a sequence of input characters that notionally matches a contextual keyword is reduced to a contextual keyword if and only if both of the following conditions hold:

   1.  The sequence is recognized as a terminal specified in a suitable context of the syntactic grammar ([2.3](https://docs.oracle.com/javase/specs/jls/se22/html/jls-2.html#jls-2.3)), as follows:
        For module and open, when recognized as a terminal in a ModuleDeclaration ([7.7](https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-7.7)).

        For module, when recognized as a terminal in a SingleModuleImportDeclaration ([7.5.5](https://cr.openjdk.org/~gbierman/jep476/jep476-20240604/specs/module-import-declarations-jls.html#jls-7.5.5)) or a ModuleDeclaration ([7.7](https://docs.oracle.com/javase/specs/jls/se22/html/jls-7.html#jls-7.7)).

As per this, the module in import module.Z shouldn't be recognized as as a contextual keyword. Copying @stephan-herrmann for weighing in.

@stephan-herrmann stephan-herrmann self-assigned this Jun 19, 2024
@stephan-herrmann
Copy link
Contributor

Thanks, @jarthana for catching this.

In fact I had prepared handling of "import module." but then forgot two things:

  • write tests for it
  • make sure it works not only in module-info.java but also in regular CU (where normally no disambiguation would happen)

stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jun 19, 2024
stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jun 20, 2024
jarthana pushed a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jun 25, 2024
sravanlakkimsetti pushed a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jun 28, 2024
stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jul 2, 2024
@stephan-herrmann stephan-herrmann added this to the BETA_JAVA23 milestone Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants