Skip to content

Teach PostTyper to handle untupled context closures #17739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great fix. Since appliedCore is now used from outside TreeInfo, it would be good to give it a doc comment.

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"))