|
1 | 1 | package dotty.tools.dotc
|
2 | 2 | package transform
|
3 | 3 |
|
4 |
| -import dotty.tools.dotc.ast.{Trees, tpd, untpd} |
| 4 | +import dotty.tools.dotc.ast.{Trees, tpd, untpd, desugar} |
5 | 5 | import scala.collection.mutable
|
6 | 6 | import core._
|
7 | 7 | import dotty.tools.dotc.typer.Checking
|
@@ -255,6 +255,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
|
255 | 255 | if tree.symbol.is(ConstructorProxy) then
|
256 | 256 | report.error(em"constructor proxy ${tree.symbol} cannot be used as a value", tree.srcPos)
|
257 | 257 |
|
| 258 | + def checkStableSelection(tree: Tree)(using Context): Unit = |
| 259 | + def check(qual: Tree) = |
| 260 | + if !qual.tpe.isStable then |
| 261 | + report.error(em"Parameter untupling cannot be used for call-by-name parameters", tree.srcPos) |
| 262 | + tree match |
| 263 | + case Select(qual, _) => check(qual) // simple select _n |
| 264 | + case Apply(TypeApply(Select(qual, _), _), _) => check(qual) // generic select .apply[T](n) |
| 265 | + |
258 | 266 | override def transform(tree: Tree)(using Context): Tree =
|
259 | 267 | try tree match {
|
260 | 268 | // TODO move CaseDef case lower: keep most probable trees first for performance
|
@@ -356,6 +364,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
|
356 | 364 | case tree: ValDef =>
|
357 | 365 | checkErasedDef(tree)
|
358 | 366 | val tree1 = cpy.ValDef(tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol))
|
| 367 | + if tree1.removeAttachment(desugar.UntupledParam).isDefined then |
| 368 | + checkStableSelection(tree.rhs) |
359 | 369 | processValOrDefDef(super.transform(tree1))
|
360 | 370 | case tree: DefDef =>
|
361 | 371 | checkErasedDef(tree)
|
|
0 commit comments