mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8154283: Check for clash between package and class not working when package in a different module
Looking for any visible package when checking for package-class clash Reviewed-by: jjg
This commit is contained in:
parent
0a3a2c3ebe
commit
d20efa360f
3 changed files with 37 additions and 6 deletions
|
@ -698,7 +698,7 @@ public class Symtab {
|
|||
*/
|
||||
public boolean packageExists(ModuleSymbol msym, Name fullname) {
|
||||
Assert.checkNonNull(msym);
|
||||
return enterPackage(msym, fullname).exists();
|
||||
return lookupPackage(msym, fullname).exists();
|
||||
}
|
||||
|
||||
/** Make a package, given its fully qualified name.
|
||||
|
|
|
@ -53,10 +53,6 @@ import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
|
|||
public class MemberEnter extends JCTree.Visitor {
|
||||
protected static final Context.Key<MemberEnter> memberEnterKey = new Context.Key<>();
|
||||
|
||||
/** A switch to determine whether we check for package/class conflicts
|
||||
*/
|
||||
final static boolean checkClash = true;
|
||||
|
||||
private final Enter enter;
|
||||
private final Log log;
|
||||
private final Check chk;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8154283
|
||||
* @summary tests for multi-module mode compilation
|
||||
* @library /tools/lib
|
||||
* @modules
|
||||
|
@ -57,7 +58,6 @@ import com.sun.tools.javac.code.Symbol.ModuleSymbol;
|
|||
import toolbox.JarTask;
|
||||
import toolbox.JavacTask;
|
||||
import toolbox.Task;
|
||||
import toolbox.ToolBox;
|
||||
|
||||
public class EdgeCases extends ModuleTestBase {
|
||||
|
||||
|
@ -269,4 +269,39 @@ public class EdgeCases extends ModuleTestBase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassPackageClash(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
Path src_m1 = src.resolve("m1");
|
||||
tb.writeJavaFiles(src_m1,
|
||||
"module m1 { exports test.m1; }",
|
||||
"package test.m1;\n" +
|
||||
"public class Test {}\n");
|
||||
Path src_m2 = src.resolve("m2");
|
||||
tb.writeJavaFiles(src_m2,
|
||||
"module m2 { requires m1; }",
|
||||
"package test;\n" +
|
||||
"public class m1 {}\n");
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
List<String> log = new JavacTask(tb)
|
||||
.options("-modulesourcepath", src.toString(),
|
||||
"-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = Arrays.asList(
|
||||
"m1.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1",
|
||||
"1 error"
|
||||
);
|
||||
|
||||
if (!expected.equals(log)) {
|
||||
throw new IllegalStateException(log.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue