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