From 311e1a4cfbcae6cab95401aac8faa07fe8381ff9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 23 Apr 2019 17:04:51 +0200 Subject: [PATCH] Avoid crashes when spliced tree does not have an Expr[T] type --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 8 ++++++-- tests/neg/quotedPatterns-4.scala | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/neg/quotedPatterns-4.scala diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index ca505ef69529..28f11a24de21 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -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 { diff --git a/tests/neg/quotedPatterns-4.scala b/tests/neg/quotedPatterns-4.scala new file mode 100644 index 000000000000..d1fae244c94d --- /dev/null +++ b/tests/neg/quotedPatterns-4.scala @@ -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 + } + } +}