From 71580306f8f5b224b70384ac35f2c5883ca45e3b Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 31 May 2023 17:20:25 +0100 Subject: [PATCH 1/2] Teach PostTyper to handle untupled context closures --- compiler/src/dotty/tools/dotc/transform/PostTyper.scala | 8 +++++--- tests/pos/i16994.scala | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i16994.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index ac3dc15092a0..ea5e7db2c088 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -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 diff --git a/tests/pos/i16994.scala b/tests/pos/i16994.scala new file mode 100644 index 000000000000..74fc62acb131 --- /dev/null +++ b/tests/pos/i16994.scala @@ -0,0 +1,2 @@ +type ZZ = String ?=> Int +def f(xs: ZZ*) = xs.zipWithIndex.foreach((f: ZZ, i) => f(using "s")) From 94a2727f3ef4ff1f05629f7fe1634654ec7b1f34 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 5 Jun 2023 14:54:49 +0100 Subject: [PATCH 2/2] Document TreeInfo's appliedCore --- compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 2d335d1ed380..1725ed5e3f94 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -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)