Skip to content

Handle symbol.defTree properly for nested definitions in bindings #11550

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

Merged
merged 1 commit into from
Mar 1, 2021
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
15 changes: 12 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
if (isByName) DefDef(boundSym, arg.changeOwner(ctx.owner, boundSym))
else ValDef(boundSym, arg)
}.withSpan(boundSym.span)
bindingsBuf += binding.setDefTree
bindingsBuf += binding
binding
}

Expand Down Expand Up @@ -521,7 +521,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
ref(rhsClsSym.sourceModule)
else
inlineCallPrefix
val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span).setDefTree
val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span)
bindingsBuf += binding
inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}")
lastSelf = selfSym
Expand Down Expand Up @@ -797,7 +797,12 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
bindingsBuf.mapInPlace { binding =>
// Set trees to symbols allow macros to see the definition tree.
// This is used by `underlyingArgument`.
reducer.normalizeBinding(binding)(using inlineCtx).setDefTree
val binding1 = reducer.normalizeBinding(binding)(using inlineCtx).setDefTree
binding1.foreachSubTree {
case tree: MemberDef => tree.setDefTree
case _ =>
}
binding1
}

// Run a typing pass over the inlined tree. See InlineTyper for details.
Expand Down Expand Up @@ -1382,6 +1387,10 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
if Inliner.needsInlining(tree) then Inliner.inlineCall(tree)
else tree

override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
super.typedUnadapted(tree, pt, locked) match
case member: MemberDef => member.setDefTree
case tree => tree
}

/** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/typer/ReTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ class ReTyper extends Typer with ReChecking {
}

override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
try super.typedUnadapted(tree, pt, locked) match
case member: MemberDef => member.setDefTree
case tree => tree
try super.typedUnadapted(tree, pt, locked)
catch {
case NonFatal(ex) =>
if ctx.phase != Phases.typerPhase && ctx.phase != Phases.inliningPhase then
Expand Down