Skip to content

Commit

Permalink
Fix inline reduction for casedef guards with asInstanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed Jan 3, 2025
1 parent 1f0c576 commit c6956b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class InlineReducer(inliner: Inliner)(using Context):
if cdef.guard.isEmpty then (true, true)
else typer.typed(cdef.guard.subst(from, to), defn.BooleanType) match {
case ConstantValue(v: Boolean) => (v, true)
case Inlined(_, _, ConstantValue(v: Boolean)) => (v, true)
case _ => (false, false)
}
if guardOK then Some((caseBindings.map(_.subst(from, to)), cdef.body.subst(from, to), canReduceGuard))
Expand Down
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)]

0 comments on commit c6956b2

Please sign in to comment.