Skip to content

Commit ba9990d

Browse files
nicolasstuckimichelou
authored andcommitted
Heal type of UnApply in quotes
Fixes scala#11211
1 parent 779ffa5 commit ba9990d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
9393
checkAnnotations(tree)
9494
healInfo(tree, tree.srcPos)
9595
super.transform(tree)
96+
case tree: UnApply =>
97+
super.transform(tree).withType(healTypeOfTerm(tree.srcPos)(tree.tpe))
9698
case tree: TypeDef if tree.symbol.is(Case) && level > 0 =>
9799
report.error(reporting.CaseClassInInlinedCode(tree), tree)
98100
super.transform(tree)

tests/pos-macros/i11211.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.quoted._
2+
def takeOptionImpl1[T](using Quotes, Type[T]): Unit = '{
3+
(??? : Option[T]) match
4+
case Some(t) => ???
5+
}
6+
7+
def takeOptionImpl2[T](using Quotes, Type[T]): Unit = '{
8+
(??? : Option[T]) match
9+
case Some(_) | None => ???
10+
}
11+
12+
def takeOptionImpl[T](o: Expr[Option[T]], default: Expr[T])(using Quotes, Type[T]): Expr[T] = '{
13+
$o match {
14+
case Some(t1) => t1
15+
case None: Option[T] => $default
16+
}
17+
}
18+
19+
inline def takeOption[T](inline o: Option[T], inline default: T) = ${takeOptionImpl('o, 'default)}

0 commit comments

Comments
 (0)