Skip to content

Commit ac70557

Browse files
authored
Merge pull request #163 from scala/backport-lts-3.3-22305
Backport "Fix inline reduction for CaseDef guards with asInstanceOf" to 3.3 LTS
2 parents d8fb35e + 4489e7e commit ac70557

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class InlineReducer(inliner: Inliner)(using Context):
362362
val (caseBindings, from, to) = substBindings(caseBindingMap.toList, mutable.ListBuffer(), Nil, Nil)
363363
val (guardOK, canReduceGuard) =
364364
if cdef.guard.isEmpty then (true, true)
365-
else typer.typed(cdef.guard.subst(from, to), defn.BooleanType) match {
365+
else stripInlined(typer.typed(cdef.guard.subst(from, to), defn.BooleanType)) match {
366366
case ConstantValue(v: Boolean) => (v, true)
367367
case _ => (false, false)
368368
}

Diff for: tests/pos/i22300.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Foo:
2+
3+
inline def inlineMatch[T]: String =
4+
inline compiletime.erasedValue[T] match
5+
case _: EmptyTuple => ""
6+
case _: (h *: _) if checkType[h](0) => ""
7+
8+
private inline def checkType[T](i: Int): Boolean =
9+
inline compiletime.erasedValue[T] match
10+
case _: Int => true
11+
case _ => false
12+
13+
val foo = Foo()
14+
15+
@main def main () =
16+
foo.inlineMatch[(Int, Boolean)]

0 commit comments

Comments
 (0)