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

[Records] ECJ doesn't allow record declarations in module-info.java #3347

Open
srikanth-sankaran opened this issue Nov 26, 2024 · 3 comments
Assignees

Comments

@srikanth-sankaran
Copy link
Contributor

For good or bad, JLS allows this. We should not reject

$ cat module-info.java
record R() {}

but we do.

@srikanth-sankaran srikanth-sankaran self-assigned this Nov 26, 2024
@srikanth-sankaran srikanth-sankaran added this to the 4.35 M1 milestone Nov 26, 2024
@srikanth-sankaran
Copy link
Contributor Author

I have disabled this test as it encodes wrong behavior:

org.eclipse.jdt.core.tests.compiler.regression.RecordsRestrictedClassTest._testBug571765_001()

@stephan-herrmann
Copy link
Contributor

stephan-herrmann commented Nov 26, 2024

For good or bad, JLS allows this.

"Allows" may be a bit too strong. JLS rarely speaks of file names, much in this area is left to the "host system".

The grammar for modular compilation units is

ModularCompilationUnit:
    {ImportDeclaration} ModuleDeclaration

No record here. So, accepting a record in module-info.java would require to interpret this file as an OrdinaryCompilationUnit.

Interestingly, the only mention of the name module-info is in JLS §7.7:

If and only if packages are stored in a file system (§7.2), the host system may choose to enforce the restriction that it is a compile-time error if a module declaration is not found in a file under a name composed of module-info plus an extension (such as .java or .jav).

Interestingly the same source code is accepted by ecj when stored in a file foo-bar.java :-P

I was wondering if we should help users to avoid such nonsense, but then I noticed that ecj already accepts normal classes in module-info.java.

<shrug/>

@srikanth-sankaran
Copy link
Contributor Author

I may have extrapolated from my recollection of how normal code is accepted in package-info.java and seeing how javac behaves with module-info

So yes my original statement may be more categorical than warranted.

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