From e0e3400ef85aa7dc6f565ef2f1662a66fbb6b7d0 Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 8 Jul 2022 11:50:59 +0200 Subject: [PATCH 1/2] 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 --- .../src/dotty/tools/dotc/typer/Checking.scala | 5 +++-- tests/pos/i15608/JavaMDCBinder.java | 20 +++++++++++++++++++ tests/pos/i15608/Test.scala | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i15608/JavaMDCBinder.java create mode 100644 tests/pos/i15608/Test.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 5a540f108420..bc9e22b8e4ed 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -1460,8 +1460,9 @@ trait Checking { report.error(ImportRenamedTwice(sel.imported), sel.imported.srcPos) seen += sel.name - for sel <- selectors do - if !sel.isWildcard then checkIdent(sel) + if !ctx.compilationUnit.isJava then + for sel <- selectors do + if !sel.isWildcard then checkIdent(sel) end checkImportSelectors } diff --git a/tests/pos/i15608/JavaMDCBinder.java b/tests/pos/i15608/JavaMDCBinder.java new file mode 100644 index 000000000000..d7ac2270e154 --- /dev/null +++ b/tests/pos/i15608/JavaMDCBinder.java @@ -0,0 +1,20 @@ +package foo.slf4j.impl; + +import bar.slf4j.MDCAdapter; +import bar.slf4j.ScalaMDCAdapter; +import bar.slf4j.ScalaMDCAdapter$; + +public class JavaMDCBinder { + public static final JavaMDCBinder SINGLETON = new JavaMDCBinder(); + + private JavaMDCBinder() { + } + + public MDCAdapter getMDCA() { + return ScalaMDCAdapter$.MODULE$; + } + + public String getMDCAdapterClassStr() { + return ScalaMDCAdapter.class.getName(); + } +} \ No newline at end of file diff --git a/tests/pos/i15608/Test.scala b/tests/pos/i15608/Test.scala new file mode 100644 index 000000000000..d357bfcd4c5c --- /dev/null +++ b/tests/pos/i15608/Test.scala @@ -0,0 +1,6 @@ +package bar.slf4j + +trait MDCAdapter + +object ScalaMDCAdapter extends MDCAdapter { +} From 747fa5c88798ae60c252dc7ced3efebf1311aae3 Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 8 Jul 2022 13:48:24 +0200 Subject: [PATCH 2/2] Fix test --- tests/pos/i15608/{ => bar}/Test.scala | 2 +- tests/pos/i15608/{ => foo}/JavaMDCBinder.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename tests/pos/i15608/{ => bar}/Test.scala (78%) rename tests/pos/i15608/{ => foo}/JavaMDCBinder.java (72%) diff --git a/tests/pos/i15608/Test.scala b/tests/pos/i15608/bar/Test.scala similarity index 78% rename from tests/pos/i15608/Test.scala rename to tests/pos/i15608/bar/Test.scala index d357bfcd4c5c..01366d02d080 100644 --- a/tests/pos/i15608/Test.scala +++ b/tests/pos/i15608/bar/Test.scala @@ -1,4 +1,4 @@ -package bar.slf4j +package bar trait MDCAdapter diff --git a/tests/pos/i15608/JavaMDCBinder.java b/tests/pos/i15608/foo/JavaMDCBinder.java similarity index 72% rename from tests/pos/i15608/JavaMDCBinder.java rename to tests/pos/i15608/foo/JavaMDCBinder.java index d7ac2270e154..58670339278e 100644 --- a/tests/pos/i15608/JavaMDCBinder.java +++ b/tests/pos/i15608/foo/JavaMDCBinder.java @@ -1,8 +1,8 @@ -package foo.slf4j.impl; +package foo; -import bar.slf4j.MDCAdapter; -import bar.slf4j.ScalaMDCAdapter; -import bar.slf4j.ScalaMDCAdapter$; +import bar.MDCAdapter; +import bar.ScalaMDCAdapter; +import bar.ScalaMDCAdapter$; public class JavaMDCBinder { public static final JavaMDCBinder SINGLETON = new JavaMDCBinder();