From 5fe11f7e2675fdbdf8e5ed5578a786cfeb075b26 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 5 Jul 2025 12:04:25 -0700 Subject: [PATCH] Don't expand name of ctor default arg --- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 5 ++++- compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala | 4 ++-- tests/pos/i23477.scala | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i23477.scala diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index bd43578e3d53..adc9432ebe0d 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -477,7 +477,10 @@ object SymDenotations { /** The expanded name of this denotation. */ final def expandedName(using Context): Name = - if (name.is(ExpandedName) || isConstructor) name + if name.is(ExpandedName) || isConstructor + || name.is(DefaultGetterName) && name.match { case DefaultGetterName(nme.CONSTRUCTOR, _) => true case _ => false } + then + name else name.expandedName(initial.owner) // need to use initial owner to disambiguate, as multiple private symbols with the same name // might have been moved from different origins into the same class diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala index 0f7dde993b17..4915d1e34897 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -25,8 +25,8 @@ import ValueClasses.* * This is necessary since private methods are not allowed to have the same name * as inherited public ones. * - * Also, make non-private any private constructor that is annotated with `@publicInBinary`. - * (See SIP-52) + * Also, make non-private any private constructor that is annotated with `@publicInBinary`. + * (See SIP-52) * * See discussion in https://github.com/scala/scala3/pull/784 * and https://github.com/scala/scala3/issues/783 diff --git a/tests/pos/i23477.scala b/tests/pos/i23477.scala new file mode 100644 index 000000000000..e1cd1a643657 --- /dev/null +++ b/tests/pos/i23477.scala @@ -0,0 +1,4 @@ +//> using options -Ycheck:expandPrivate + +class C private (x: Int, y: Int = 1): + def this() = this(1)