Skip to content

Commit

Permalink
8332890: Module imports don't work inside the same module
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
lahodaj committed May 27, 2024
1 parent 793fd72 commit 08face8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,9 @@ private void initVisiblePackages(ModuleSymbol msym, Collection<ModuleSymbol> rea
addVisiblePackages(msym, seen, exportsFrom, exports);
}
});

//module readability is reflexive:
msym.readModules.add(msym);
}

private void addVisiblePackages(ModuleSymbol msym,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ private void doModuleImport(JCModuleImport tree) {
}

for (ExportsDirective export : currentModule.exports) {
if (export.modules != null && !export.modules.contains(env.toplevel.packge.modle)) {
if (export.modules != null && !export.modules.contains(env.toplevel.modle)) {
continue;
}

Expand Down
58 changes: 57 additions & 1 deletion test/langtools/tools/javac/ImportModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @test
* @bug 8328481 8332236
* @bug 8328481 8332236 8332890
* @summary Check behavior of module imports.
* @library /tools/lib
* @modules java.logging
Expand Down Expand Up @@ -741,4 +741,60 @@ void main() {
.writeAll();
}

@Test //JDK-8332890
public void testModuleInfoSelfImport(Path base) throws Exception {
Path current = base.resolve(".");
Path src = current.resolve("src");
Path classes = current.resolve("classes");
tb.writeJavaFiles(src,
"""
import module M;
module M {
exports p1 to M1;
exports p2;
exports p3 to M;
uses A;
uses B;
uses C;
}
""",
"""
package p1;
public class A {}
""",
"""
package p2;
public class B {}
""",
"""
package p3;
public class C {}
""");

Files.createDirectories(classes);

List<String> actualErrors = new JavacTask(tb)
.options("-XDrawDiagnostics",
"--enable-preview", "--release", SOURCE_VERSION)
.outdir(classes)
.files(tb.findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutputLines(Task.OutputKind.DIRECT);

List<String> expectedErrors = List.of(
"module-info.java:3:18: compiler.warn.module.not.found: M1",
"module-info.java:6:9: compiler.err.cant.resolve: kindname.class, A, , ",
"- compiler.note.preview.filename: module-info.java, DEFAULT",
"- compiler.note.preview.recompile",
"1 error",
"1 warning"
);

if (!Objects.equals(expectedErrors, actualErrors)) {
throw new AssertionError("Incorrect Output, expected: " + expectedErrors +
", actual: " + out);

}
}
}

0 comments on commit 08face8

Please sign in to comment.