From da176c326fbad4468a7acdcc6fb5df2a80f0c46b Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Mon, 16 Dec 2024 11:59:46 +0100 Subject: [PATCH] Only count associated files of direct members of package objects in dropStale (#22190) possible fix for #17394 --- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 4 +++- tests/pos/i17394/_1.scala | 9 +++++++++ tests/pos/i17394/_2.scala | 4 ++++ tests/pos/i17394b/_1.scala | 9 +++++++++ tests/pos/i17394b/_2.scala | 5 +++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i17394/_1.scala create mode 100644 tests/pos/i17394/_2.scala create mode 100644 tests/pos/i17394b/_1.scala create mode 100644 tests/pos/i17394b/_2.scala diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index e14e5cf0a728..be651842d9b0 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2539,7 +2539,9 @@ object SymDenotations { ) if compiledNow.exists then compiledNow else - val assocFiles = multi.aggregate(d => Set(d.symbol.associatedFile.nn), _ union _) + val assocFiles = multi + .filterWithPredicate(_.symbol.maybeOwner.isPackageObject) + .aggregate(d => Set(d.symbol.associatedFile.nn), _ union _) if assocFiles.size == 1 then multi // they are all overloaded variants from the same file else diff --git a/tests/pos/i17394/_1.scala b/tests/pos/i17394/_1.scala new file mode 100644 index 000000000000..fdab17ec3f19 --- /dev/null +++ b/tests/pos/i17394/_1.scala @@ -0,0 +1,9 @@ +package example: + def xd: Int = ??? + +package bar: + trait A: + def foo: String = ??? + +package object example extends bar.A: + def foo(x: String): String = ??? diff --git a/tests/pos/i17394/_2.scala b/tests/pos/i17394/_2.scala new file mode 100644 index 000000000000..5ac6a31a66b2 --- /dev/null +++ b/tests/pos/i17394/_2.scala @@ -0,0 +1,4 @@ +import example.* + +@main def main = + val _ = foo diff --git a/tests/pos/i17394b/_1.scala b/tests/pos/i17394b/_1.scala new file mode 100644 index 000000000000..fdab17ec3f19 --- /dev/null +++ b/tests/pos/i17394b/_1.scala @@ -0,0 +1,9 @@ +package example: + def xd: Int = ??? + +package bar: + trait A: + def foo: String = ??? + +package object example extends bar.A: + def foo(x: String): String = ??? diff --git a/tests/pos/i17394b/_2.scala b/tests/pos/i17394b/_2.scala new file mode 100644 index 000000000000..8c86ca45e215 --- /dev/null +++ b/tests/pos/i17394b/_2.scala @@ -0,0 +1,5 @@ +//> using options -Wunused:imports + +import example.{given, *} + +@main def main = ()