Skip to content

Commit e0e3400

Browse files
committed
Don't check import selectors for Java code
Moving import selector checking from PostTyper to Typer had the side-effect that they were also checked in Java code. But that does not work since the Java files are compiled before the Scala files so the selected reference has not been seen yet. Fixed by disabling import selector checks for Java files. Fixes #15608
1 parent 1724d84 commit e0e3400

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,9 @@ trait Checking {
14601460
report.error(ImportRenamedTwice(sel.imported), sel.imported.srcPos)
14611461
seen += sel.name
14621462

1463-
for sel <- selectors do
1464-
if !sel.isWildcard then checkIdent(sel)
1463+
if !ctx.compilationUnit.isJava then
1464+
for sel <- selectors do
1465+
if !sel.isWildcard then checkIdent(sel)
14651466
end checkImportSelectors
14661467
}
14671468

tests/pos/i15608/JavaMDCBinder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package foo.slf4j.impl;
2+
3+
import bar.slf4j.MDCAdapter;
4+
import bar.slf4j.ScalaMDCAdapter;
5+
import bar.slf4j.ScalaMDCAdapter$;
6+
7+
public class JavaMDCBinder {
8+
public static final JavaMDCBinder SINGLETON = new JavaMDCBinder();
9+
10+
private JavaMDCBinder() {
11+
}
12+
13+
public MDCAdapter getMDCA() {
14+
return ScalaMDCAdapter$.MODULE$;
15+
}
16+
17+
public String getMDCAdapterClassStr() {
18+
return ScalaMDCAdapter.class.getName();
19+
}
20+
}

tests/pos/i15608/Test.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package bar.slf4j
2+
3+
trait MDCAdapter
4+
5+
object ScalaMDCAdapter extends MDCAdapter {
6+
}

0 commit comments

Comments
 (0)