Skip to content

Backport "Fix inline reduction for CaseDef guards with asInstanceOf" to 3.3 LTS #163

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 1 commit into from
Mar 14, 2025
Merged
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala
Original file line number Diff line number Diff line change
@@ -362,7 +362,7 @@ class InlineReducer(inliner: Inliner)(using Context):
val (caseBindings, from, to) = substBindings(caseBindingMap.toList, mutable.ListBuffer(), Nil, Nil)
val (guardOK, canReduceGuard) =
if cdef.guard.isEmpty then (true, true)
else typer.typed(cdef.guard.subst(from, to), defn.BooleanType) match {
else stripInlined(typer.typed(cdef.guard.subst(from, to), defn.BooleanType)) match {
case ConstantValue(v: Boolean) => (v, true)
case _ => (false, false)
}
16 changes: 16 additions & 0 deletions tests/pos/i22300.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Foo:

inline def inlineMatch[T]: String =
inline compiletime.erasedValue[T] match
case _: EmptyTuple => ""
case _: (h *: _) if checkType[h](0) => ""

private inline def checkType[T](i: Int): Boolean =
inline compiletime.erasedValue[T] match
case _: Int => true
case _ => false

val foo = Foo()

@main def main () =
foo.inlineMatch[(Int, Boolean)]