Skip to content

Handle alternative patterns in inline reduction #12137

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
Apr 20, 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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
case _ =>
false
}
case Alternative(pats) =>
pats.exists(reducePattern(caseBindingMap, scrut, _))
case Inlined(EmptyTree, Nil, ipat) =>
reducePattern(caseBindingMap, scrut, ipat)
case _ => false
Expand Down
70 changes: 70 additions & 0 deletions tests/pos/i12073.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
inline def ff: Unit =
inline 1 match
case 1 | 2 =>

def test = ff

transparent inline def f: Option[String] =
None

object Override {

trait Trait { def s: String }

object OK extends Trait {
override transparent inline def s: String =
inline f match {
case Some("x") => "x"
case Some("y") => "y"
case None => "-"
}
}

object KO_1 extends Trait {
override transparent inline def s: String =
inline f match {
case Some("x") => "x"
case Some("y")
| None => "0"
}
}

object KO_2 extends Trait {
override transparent inline def s: String =
inline f match {
case Some("x") => "x"
case Some("y") => "y"
case Some(z) => "z"
case None => "0"
}
}
}

object NonOverride {

transparent inline def ok_1: String =
inline f match {
case Some("x") => "x"
case Some("y") => "y"
case None => "-"
}

// ok: Some("y") | None
transparent inline def ok_2: String =
inline f match {
case Some("x") => "x"
case Some("y")
| None => "0"
}

// ok: no None
transparent inline def ok_3: String =
inline f match {
case Some("x") => "x"
case Some("y") => "y"
case Some(z) => "z"
case None => "0"
}

ok_1 + ok_2 ++ ok_3
}