Skip to content

Fix #6325: Propagate error type to internal splice #6326

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 2 commits into from
Apr 18, 2019
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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
/** An extractor for typed splices */
object Splice {
def apply(tree: Tree)(implicit ctx: Context): Tree = {
val argType = tree.tpe.baseType(defn.QuotedExprClass).argTypesHi.head
val argType =
if (tree.tpe.widen.isError) tree.tpe.widen
else tree.tpe.baseType(defn.QuotedExprClass).argTypesHi.head
ref(defn.InternalQuoted_exprSplice).appliedToType(argType).appliedTo(tree)
}
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {
Expand Down
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2011,12 +2011,16 @@ class Typer extends Namer
typed(innerExpr, pt)
case expr =>
if (ctx.mode.is(Mode.QuotedPattern) && level == 1) {
fullyDefinedType(pt, "quoted pattern selector", tree.span)
def spliceOwner(ctx: Context): Symbol =
if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner
val pat = typedPattern(expr, defn.QuotedExprType.appliedTo(pt))(
spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
Splice(pat)
if (isFullyDefined(pt, ForceDegree.all)) {
def spliceOwner(ctx: Context): Symbol =
if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner
val pat = typedPattern(expr, defn.QuotedExprType.appliedTo(pt))(
spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
Splice(pat)
} else {
ctx.error(i"Type must be fully defined.\nConsider annotating the splice using a type ascription:\n ($tree: XYZ).", expr.sourcePos)
tree.withType(UnspecifiedErrorType)
}
}
else
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext).withSpan(tree.span)
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i6324.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Test {
def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match {
case '{ 1 + $b } => // error: Type must be fully defined. Consider annotating the splice using a type ascription: (${b}: XYZ).
b // error: Not found: b
}
}
7 changes: 7 additions & 0 deletions tests/neg/i6325.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//import scala.quoted.matching.Bind
object Test {
def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match {
case '{ 1 + (${Bind(b)}: Int) } => ??? // error: Not found: Bind
case _ => ???
}
}