Skip to content

Avoid crashes when spliced tree does not have an Expr[T] type #6364

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
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
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
/** An extractor for typed splices */
object Splice {
def apply(tree: Tree)(implicit ctx: Context): Tree = {
val baseType = tree.tpe.baseType(defn.QuotedExprClass)
val argType =
if (tree.tpe.widen.isError) tree.tpe.widen
else tree.tpe.baseType(defn.QuotedExprClass).argTypesHi.head
if (baseType != NoType) baseType.argTypesHi.head
else {
assert(ctx.reporter.hasErrors)
defn.NothingType
}
ref(defn.InternalQuoted_exprSplice).appliedToType(argType).appliedTo(tree)
}
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/quotedPatterns-4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.quoted._
object Test {
def impl(receiver: Expr[StringContext])(implicit reflect: scala.tasty.Reflection) = {
import reflect.Repeated
receiver match {
case '{ StringContext(${Repeated(parts)}: _*) } => // error
}
}
}