Skip to content

Commit de42177

Browse files
committed
Do not widen selector type in inline matches
Fixes #12715
1 parent d7d4a9f commit de42177

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,8 @@ class Typer extends Namer
14651465
case _ =>
14661466
if tree.isInline then checkInInlineContext("inline match", tree.srcPos)
14671467
val sel1 = typedExpr(tree.selector)
1468-
val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.span).widen
1469-
1468+
val rawSelectorTpe = fullyDefinedType(sel1.tpe, "pattern selector", tree.span)
1469+
val selType = if (tree.isInline) rawSelectorTpe else rawSelectorTpe.widen
14701470
/** Extractor for match types hidden behind an AppliedType/MatchAlias */
14711471
object MatchTypeInDisguise {
14721472
def unapply(tp: AppliedType): Option[MatchType] = tp match {

tests/pos/i12715.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
transparent inline def f: String =
2+
inline 10 match
3+
case _ =>
4+
inline "foo" match
5+
case x : String => x
6+
7+
def test =
8+
inline val failMsg = f

0 commit comments

Comments
 (0)