Skip to content

Fix #12188: Use ascribed type for bindings #12190

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 27, 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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ class SpaceEngine(using Context) extends SpaceLogic {
case Typed(pat @ UnApply(_, _, _), _) =>
project(pat)

case Typed(expr, _) =>
Typ(erase(expr.tpe.stripAnnots), true)
case Typed(_, tpt) =>
Typ(erase(tpt.tpe.stripAnnots), true)

case This(_) =>
Typ(pat.tpe.stripAnnots, false)
Expand Down
20 changes: 20 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i12188/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import scala.quoted.*

object MatchTest {
inline def test[T](inline obj: T): Unit = ${testImpl('obj)}

def testImpl[T](objExpr: Expr[T])(using qctx: Quotes, t: Type[T]): Expr[Unit] = {
import qctx.reflect.*

val obj = objExpr.asTerm

val cases = obj.tpe.typeSymbol.children.map { child =>
val subtype = TypeIdent(child)
val bind = Symbol.newBind(Symbol.spliceOwner, "c", Flags.EmptyFlags, subtype.tpe)
CaseDef(Bind(bind, Typed(Ref(bind), subtype)), None, '{()}.asTerm)
}
val result = Match(obj, cases)
println(result.show(using Printer.TreeAnsiCode))
result.asExprOf[Unit]
}
}
9 changes: 9 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i12188/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sealed trait P
case class PC1(a: String) extends P
case class PC2(b: Int) extends P

def Test = MatchTest.test(PC2(10): P)

def foo(x: P): Unit =
x match // error
case _: PC1 =>