Skip to content

Commit 55da939

Browse files
authored
Merge pull request #11550 from dotty-staging/improve-deftree
Handle symbol.defTree properly for nested definitions in bindings
2 parents 9632f6b + 8ab5f00 commit 55da939

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

+12-3
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
465465
if (isByName) DefDef(boundSym, newArg)
466466
else ValDef(boundSym, newArg)
467467
}.withSpan(boundSym.span)
468-
bindingsBuf += binding.setDefTree
468+
bindingsBuf += binding
469469
binding
470470
}
471471

@@ -522,7 +522,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
522522
ref(rhsClsSym.sourceModule)
523523
else
524524
inlineCallPrefix
525-
val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span).setDefTree
525+
val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span)
526526
bindingsBuf += binding
527527
inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}")
528528
lastSelf = selfSym
@@ -798,7 +798,12 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
798798
bindingsBuf.mapInPlace { binding =>
799799
// Set trees to symbols allow macros to see the definition tree.
800800
// This is used by `underlyingArgument`.
801-
reducer.normalizeBinding(binding)(using inlineCtx).setDefTree
801+
val binding1 = reducer.normalizeBinding(binding)(using inlineCtx).setDefTree
802+
binding1.foreachSubTree {
803+
case tree: MemberDef => tree.setDefTree
804+
case _ =>
805+
}
806+
binding1
802807
}
803808

804809
// Run a typing pass over the inlined tree. See InlineTyper for details.
@@ -1383,6 +1388,10 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
13831388
if Inliner.needsInlining(tree) then Inliner.inlineCall(tree)
13841389
else tree
13851390

1391+
override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
1392+
super.typedUnadapted(tree, pt, locked) match
1393+
case member: MemberDef => member.setDefTree
1394+
case tree => tree
13861395
}
13871396

13881397
/** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.

compiler/src/dotty/tools/dotc/typer/ReTyper.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ class ReTyper extends Typer with ReChecking {
115115
}
116116

117117
override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
118-
try super.typedUnadapted(tree, pt, locked) match
119-
case member: MemberDef => member.setDefTree
120-
case tree => tree
118+
try super.typedUnadapted(tree, pt, locked)
121119
catch {
122120
case NonFatal(ex) =>
123121
if ctx.phase != Phases.typerPhase && ctx.phase != Phases.inliningPhase then

0 commit comments

Comments
 (0)