Skip to content

Commit

Permalink
Teach PostTyper to handle untupled context closures (#17739)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored Jun 6, 2023
2 parents 58127a3 + 94a2727 commit 0749271
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
case _ => p(tree)
}

/** The tree stripped of the possibly nested applications (term and type).
* The original tree if it's not an application.
*/
def appliedCore(tree: Tree): Tree = tree match {
case Apply(fn, _) => appliedCore(fn)
case TypeApply(fn, _) => appliedCore(fn)
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
def check(qual: Tree) =
if !qual.tpe.isStable then
report.error(em"Parameter untupling cannot be used for call-by-name parameters", tree.srcPos)
tree match
case Select(qual, _) => check(qual) // simple select _n
case Apply(TypeApply(Select(qual, _), _), _) => check(qual) // generic select .apply[T](n)
appliedCore(closureBody(tree)) match
case Select(qual, _) => check(qual)
// simple select _n Select(qual, _n)
// generic select .apply[T](n) Apply(TypeApply(Select(qual, _), _), _)
// context closure x ?=> f(using x) Block(List(DefDef($anonfun, _, _, Apply(Select(Select(qual, _n), _), _)))

def checkNotPackage(tree: Tree)(using Context): Tree =
if !tree.symbol.is(Package) then tree
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/i16994.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type ZZ = String ?=> Int
def f(xs: ZZ*) = xs.zipWithIndex.foreach((f: ZZ, i) => f(using "s"))

0 comments on commit 0749271

Please sign in to comment.