Skip to content

Commit 7158030

Browse files
committed
Teach PostTyper to handle untupled context closures
1 parent d0b790e commit 7158030

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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)