Skip to content

Commit 1896c2b

Browse files
Merge pull request #8912 from dotty-staging/fix-#8892
Fix #8892: Fix position adjustments in Inliner
2 parents 5a276ac + 52e0b4b commit 1896c2b

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
119119
def cloneIn(src: SourceFile): this.type = {
120120
val newpd: this.type = clone.asInstanceOf[this.type]
121121
newpd.uniqueId = src.nextId
122+
// assert(newpd.uniqueId != 2208, s"source = $this, ${this.uniqueId}, ${this.span}")
122123
newpd
123124
}
124125

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Names._, StdNames._, NameOps._, Symbols._
88
import typer.ConstFold
99
import reporting.trace
1010
import dotty.tools.dotc.transform.SymUtils._
11+
import Decorators._
1112

1213
import scala.annotation.tailrec
1314

@@ -836,6 +837,12 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
836837
}
837838
}
838839

840+
def assertAllPositioned(tree: Tree)(using Context): Unit =
841+
tree.foreachSubTree {
842+
case t: WithoutTypeOrPos[_] =>
843+
case t => assert(t.span.exists, i"$t")
844+
}
845+
839846
/** Extractors for quotes */
840847
object Quoted {
841848
/** Extracts the content of a quoted tree.

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ object Trees {
10441044
def Apply(tree: Tree)(fun: Tree, args: List[Tree])(implicit ctx: Context): Apply = tree match {
10451045
case tree: Apply if (fun eq tree.fun) && (args eq tree.args) => tree
10461046
case _ => finalize(tree, untpd.Apply(fun, args)(sourceFile(tree)))
1047+
//.ensuring(res => res.uniqueId != 2213, s"source = $tree, ${tree.uniqueId}, ${tree.span}")
10471048
}
10481049
def TypeApply(tree: Tree)(fun: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = tree match {
10491050
case tree: TypeApply if (fun eq tree.fun) && (args eq tree.args) => tree
@@ -1060,7 +1061,6 @@ object Trees {
10601061
def Typed(tree: Tree)(expr: Tree, tpt: Tree)(implicit ctx: Context): Typed = tree match {
10611062
case tree: Typed if (expr eq tree.expr) && (tpt eq tree.tpt) => tree
10621063
case tree => finalize(tree, untpd.Typed(expr, tpt)(sourceFile(tree)))
1063-
//.ensuring(res => res.uniqueId != 1471, s"source = $tree, ${tree.uniqueId}")
10641064
}
10651065
def NamedArg(tree: Tree)(name: Name, arg: Tree)(implicit ctx: Context): NamedArg = tree match {
10661066
case tree: NamedArg if (name == tree.name) && (arg eq tree.arg) => tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ object Inliner {
7575
* inlined call `call` to the position of `call`. This transform is necessary
7676
* when lifting bindings from the expansion to the outside of the call.
7777
*/
78-
def liftFromInlined(call: Tree) = new TreeMap {
78+
def liftFromInlined(call: Tree) = new TreeMap:
7979
override def transform(t: Tree)(using Context) =
80-
t match {
81-
case Inlined(t, Nil, expr) if t.isEmpty => expr
82-
case _ if t.isEmpty => t
83-
case _ => super.transform(t.withSpan(call.span))
84-
}
85-
}
80+
if call.span.exists then
81+
t match
82+
case Inlined(t, Nil, expr) if t.isEmpty => expr
83+
case _ if t.isEmpty => t
84+
case _ => super.transform(t.withSpan(call.span))
85+
else t
86+
end liftFromInlined
8687

8788
val bindings = new mutable.ListBuffer[Tree]
8889

@@ -108,6 +109,7 @@ object Inliner {
108109
tree
109110
}
110111

112+
// assertAllPositioned(tree) // debug
111113
val tree1 = liftBindings(tree, identity)
112114
if (bindings.nonEmpty)
113115
cpy.Block(tree)(bindings.toList, inlineCall(tree1))
@@ -590,6 +592,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
590592
* itself, it has to be marked as an inlined argument.
591593
*/
592594
def integrate(tree: Tree, originalOwner: Symbol)(using Context): Tree =
595+
// assertAllPositioned(tree) // debug
593596
tree.changeOwner(originalOwner, ctx.owner)
594597

595598
def tryConstValue: Tree =

tests/pos/i8892.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
trait Reporter:
2+
def report(m: String): Unit
3+
4+
class Dummy extends Reporter:
5+
def report(m: String) = ()
6+
7+
object ABug {
8+
sealed trait Nat {
9+
inline def ++ : Succ[this.type] = Succ(this)
10+
11+
transparent inline def +(inline that: Nat): Nat =
12+
inline this match {
13+
case Zero => that
14+
case Succ(p) => p + that.++
15+
}
16+
}
17+
18+
case object Zero extends Nat
19+
case class Succ[N <: Nat](p: N) extends Nat
20+
21+
transparent inline def toIntg(inline n: Nat): Int =
22+
inline n match {
23+
case Zero => 0
24+
case Succ(p) => toIntg(p) + 1
25+
}
26+
27+
val j31 = toIntg(Zero.++.++.++ + Zero.++)
28+
}

0 commit comments

Comments
 (0)