Skip to content

Commit db7e411

Browse files
Merge pull request #6364 from dotty-staging/fix-crash-after-error-reported
Avoid crashes when spliced tree does not have an Expr[T] type
2 parents 72e5145 + 311e1a4 commit db7e411

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11811181
/** An extractor for typed splices */
11821182
object Splice {
11831183
def apply(tree: Tree)(implicit ctx: Context): Tree = {
1184+
val baseType = tree.tpe.baseType(defn.QuotedExprClass)
11841185
val argType =
1185-
if (tree.tpe.widen.isError) tree.tpe.widen
1186-
else tree.tpe.baseType(defn.QuotedExprClass).argTypesHi.head
1186+
if (baseType != NoType) baseType.argTypesHi.head
1187+
else {
1188+
assert(ctx.reporter.hasErrors)
1189+
defn.NothingType
1190+
}
11871191
ref(defn.InternalQuoted_exprSplice).appliedToType(argType).appliedTo(tree)
11881192
}
11891193
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {

tests/neg/quotedPatterns-4.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted._
2+
object Test {
3+
def impl(receiver: Expr[StringContext])(implicit reflect: scala.tasty.Reflection) = {
4+
import reflect.Repeated
5+
receiver match {
6+
case '{ StringContext(${Repeated(parts)}: _*) } => // error
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)