Skip to content
Open
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
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case block @ Block(stats, expr) if !expr.isInstanceOf[Closure] =>
val expr1 = ascribeType(expr, pt)
cpy.Block(block)(stats, expr1).withType(expr1.tpe) // no assignType here because avoid is redundant
case m @ Match(selector, cases) if m.isSubMatch =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we only need to handle SubMatch here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of how transformMatch handles a simple Match vs SubMatch. For the first one, wrapping it in Typed is not a problem

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this case is added to avoid the Typed wrapper?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly

val newCases = cases.map: cdef =>
val newBody = ascribeType(cdef.body, pt)
cpy.CaseDef(cdef)(body = newBody).withType(newBody.tpe)
cpy.Match(m)(selector, newCases).withType(TypeComparer.lub(newCases.tpes))
case _ =>
val target = pt.simplified
val targetTpt = TypeTree(target, inferred = true)
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/scoverage-ignore.excludelist
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ tailrec.scala
traitParams.scala
i25460.scala
matrix.scala
i25746.scala
9 changes: 9 additions & 0 deletions tests/pos/i25746.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.language.experimental.subCases

@main def test =
val r1 = "^foo".r.unanchored
val r2 = "bar$".r.unanchored

val result1 = "foo bar" match
case s @ r1() if s match { case r2() => s }
case _ => "no"
Loading