Skip to content

Heal type of UnApply in quotes #11301

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 1 commit into from
Feb 4, 2021
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
checkAnnotations(tree)
healInfo(tree, tree.srcPos)
super.transform(tree)
case tree: UnApply =>
super.transform(tree).withType(healTypeOfTerm(tree.srcPos)(tree.tpe))
case tree: TypeDef if tree.symbol.is(Case) && level > 0 =>
report.error(reporting.CaseClassInInlinedCode(tree), tree)
super.transform(tree)
Expand Down
19 changes: 19 additions & 0 deletions tests/pos-macros/i11211.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import scala.quoted._
def takeOptionImpl1[T](using Quotes, Type[T]): Unit = '{
(??? : Option[T]) match
case Some(t) => ???
}

def takeOptionImpl2[T](using Quotes, Type[T]): Unit = '{
(??? : Option[T]) match
case Some(_) | None => ???
}

def takeOptionImpl[T](o: Expr[Option[T]], default: Expr[T])(using Quotes, Type[T]): Expr[T] = '{
$o match {
case Some(t1) => t1
case None: Option[T] => $default
}
}

inline def takeOption[T](inline o: Option[T], inline default: T) = ${takeOptionImpl('o, 'default)}