Skip to content

Commit 5fe11f7

Browse files
committed
Don't expand name of ctor default arg
1 parent c0bdc56 commit 5fe11f7

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@ object SymDenotations {
477477

478478
/** The expanded name of this denotation. */
479479
final def expandedName(using Context): Name =
480-
if (name.is(ExpandedName) || isConstructor) name
480+
if name.is(ExpandedName) || isConstructor
481+
|| name.is(DefaultGetterName) && name.match { case DefaultGetterName(nme.CONSTRUCTOR, _) => true case _ => false }
482+
then
483+
name
481484
else name.expandedName(initial.owner)
482485
// need to use initial owner to disambiguate, as multiple private symbols with the same name
483486
// might have been moved from different origins into the same class

compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import ValueClasses.*
2525
* This is necessary since private methods are not allowed to have the same name
2626
* as inherited public ones.
2727
*
28-
* Also, make non-private any private constructor that is annotated with `@publicInBinary`.
29-
* (See SIP-52)
28+
* Also, make non-private any private constructor that is annotated with `@publicInBinary`.
29+
* (See SIP-52)
3030
*
3131
* See discussion in https://github.com/scala/scala3/pull/784
3232
* and https://github.com/scala/scala3/issues/783

tests/pos/i23477.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//> using options -Ycheck:expandPrivate
2+
3+
class C private (x: Int, y: Int = 1):
4+
def this() = this(1)

0 commit comments

Comments
 (0)