Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Use constructor's default getters in case class synthetic apply methods" to LTS #20725

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1137,11 +1137,16 @@ class Namer { typer: Typer =>

def foreachDefaultGetterOf(sym: TermSymbol, op: TermSymbol => Unit): Unit =
var n = 0
val methodName =
if sym.name == nme.apply && sym.is(Synthetic) && sym.owner.companionClass.is(Case) then
// The synthesized `apply` methods of case classes use the constructor's default getters
nme.CONSTRUCTOR
else sym.name
for params <- sym.paramSymss; param <- params do
if param.isTerm then
if param.is(HasDefault) then
val getterName = DefaultGetterName(sym.name, n)
val getter = pathType.member(DefaultGetterName(sym.name, n)).symbol
val getterName = DefaultGetterName(methodName, n)
val getter = pathType.member(getterName).symbol
assert(getter.exists, i"$path does not have a default getter named $getterName")
op(getter.asTerm)
n += 1
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i18715.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
case class Foo(x: Int = 0)

extension (x: Any)
private def foo = Foo
export foo.apply
Loading