Skip to content

Commit 0749271

Browse files
authored
Teach PostTyper to handle untupled context closures (#17739)
2 parents 58127a3 + 94a2727 commit 0749271

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
330330
case _ => p(tree)
331331
}
332332

333+
/** The tree stripped of the possibly nested applications (term and type).
334+
* The original tree if it's not an application.
335+
*/
333336
def appliedCore(tree: Tree): Tree = tree match {
334337
case Apply(fn, _) => appliedCore(fn)
335338
case TypeApply(fn, _) => appliedCore(fn)

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
261261
def check(qual: Tree) =
262262
if !qual.tpe.isStable then
263263
report.error(em"Parameter untupling cannot be used for call-by-name parameters", tree.srcPos)
264-
tree match
265-
case Select(qual, _) => check(qual) // simple select _n
266-
case Apply(TypeApply(Select(qual, _), _), _) => check(qual) // generic select .apply[T](n)
264+
appliedCore(closureBody(tree)) match
265+
case Select(qual, _) => check(qual)
266+
// simple select _n Select(qual, _n)
267+
// generic select .apply[T](n) Apply(TypeApply(Select(qual, _), _), _)
268+
// context closure x ?=> f(using x) Block(List(DefDef($anonfun, _, _, Apply(Select(Select(qual, _n), _), _)))
267269

268270
def checkNotPackage(tree: Tree)(using Context): Tree =
269271
if !tree.symbol.is(Package) then tree

tests/pos/i16994.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type ZZ = String ?=> Int
2+
def f(xs: ZZ*) = xs.zipWithIndex.foreach((f: ZZ, i) => f(using "s"))

0 commit comments

Comments
 (0)