Skip to content

Commit 6e8b355

Browse files
authored
Fix Function tree copier (#19822)
It did not copy correctly instances of the FunctionWithMods subclass. Fixes #19751
2 parents 1191671 + cd68604 commit 6e8b355

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -1967,10 +1967,7 @@ object desugar {
19671967
val applyVParams = args.zipWithIndex.map {
19681968
case (p, n) => makeSyntheticParameter(n + 1, p)
19691969
}
1970-
tree match
1971-
case tree: FunctionWithMods =>
1972-
untpd.FunctionWithMods(applyVParams, result, tree.mods, tree.erasedParams)
1973-
case _ => untpd.Function(applyVParams, result)
1970+
cpy.Function(tree)(applyVParams, result).asInstanceOf[untpd.Function]
19741971
}
19751972
}
19761973

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

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

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,11 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
614614
}
615615
def Function(tree: Tree)(args: List[Tree], body: Tree)(using Context): Tree = tree match {
616616
case tree: Function if (args eq tree.args) && (body eq tree.body) => tree
617-
case _ => finalize(tree, untpd.Function(args, body)(tree.source))
617+
case _ =>
618+
val tree1 = tree match
619+
case tree: FunctionWithMods => untpd.FunctionWithMods(args, body, tree.mods, tree.erasedParams)(using tree.source)
620+
case _ => untpd.Function(args, body)(using tree.source)
621+
finalize(tree, tree1)
618622
}
619623
def PolyFunction(tree: Tree)(targs: List[Tree], body: Tree)(using Context): Tree = tree match {
620624
case tree: PolyFunction if (targs eq tree.targs) && (body eq tree.body) => tree
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)