Skip to content

Commit 63146b4

Browse files
committed
Fix Function tree copier
It did not copy correctly instances of the FunctionWithMods subclass. Fixes #19751
1 parent 8b8caa9 commit 63146b4

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,12 @@ object Trees {
12541254
case _ => finalize(tree, untpd.Ident(name)(sourceFile(tree)))
12551255
}
12561256
def Select(tree: Tree)(qualifier: Tree, name: Name)(using Context): Select = tree match {
1257-
case tree: SelectWithSig =>
1258-
if ((qualifier eq tree.qualifier) && (name == tree.name)) tree
1259-
else finalize(tree, SelectWithSig(qualifier, name, tree.sig)(sourceFile(tree)))
12601257
case tree: Select if (qualifier eq tree.qualifier) && (name == tree.name) => tree
1261-
case _ => finalize(tree, untpd.Select(qualifier, name)(sourceFile(tree)))
1258+
case _ =>
1259+
val tree1 = tree match
1260+
case tree: SelectWithSig => untpd.SelectWithSig(qualifier, name, tree.sig)(using sourceFile(tree))
1261+
case _ => untpd.Select(qualifier, name)(using sourceFile(tree))
1262+
finalize(tree, tree1)
12621263
}
12631264
/** Copy Ident or Select trees */
12641265
def Ref(tree: RefTree)(name: Name)(using Context): RefTree = tree match {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,11 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
609609
}
610610
def Function(tree: Tree)(args: List[Tree], body: Tree)(using Context): Tree = tree match {
611611
case tree: Function if (args eq tree.args) && (body eq tree.body) => tree
612-
case _ => finalize(tree, untpd.Function(args, body)(tree.source))
612+
case _ =>
613+
val tree1 = tree match
614+
case tree: FunctionWithMods => untpd.FunctionWithMods(args, body, tree.mods, tree.erasedParams)(using tree.source)
615+
case _ => untpd.Function(args, body)(using tree.source)
616+
finalize(tree, tree1)
613617
}
614618
def PolyFunction(tree: Tree)(targs: List[Tree], body: Tree)(using Context): Tree = tree match {
615619
case tree: PolyFunction if (targs eq tree.targs) && (body eq tree.body) => tree
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import language.experimental.captureChecking
2+
import annotation.capability
3+
import caps.cap
4+
5+
trait Ptr[A]
6+
@capability trait Scope:
7+
def allocate(size: Int): Ptr[Unit]^{this}
8+
9+
10+
object Scope:
11+
def confined[A](fn: Scope ?->{cap} A): A =
12+
val scope = new Scope:
13+
def allocate(size: Int) = new Ptr[Unit] {}
14+
fn(using scope)
15+
16+
def Test: Unit =
17+
val s = Scope.confined:
18+
val s2 = summon[Scope]
19+
Scope.confined:
20+
s2.allocate(5)
21+
5
22+

0 commit comments

Comments
 (0)