Skip to content

Commit fd95c55

Browse files
authored
Avoid over widening in SpaceEngine (#18252)
2 parents 816bd5e + 6bea14b commit fd95c55

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,13 @@ object SpaceEngine {
578578
if (arity > 0)
579579
productSelectorTypes(resTp, unappSym.srcPos)
580580
else {
581-
val getTp = resTp.select(nme.get).finalResultType.widenTermRefExpr
581+
val getTp = resTp.select(nme.get).finalResultType match
582+
case tp: TermRef if !tp.isOverloaded =>
583+
// Like widenTermRefExpr, except not recursively.
584+
// For example, in i17184 widen Option[foo.type]#get
585+
// to Option[foo.type] instead of Option[Int].
586+
tp.underlying.widenExpr
587+
case tp => tp
582588
if (argLen == 1) getTp :: Nil
583589
else productSelectorTypes(getTp, unappSym.srcPos)
584590
}

tests/patmat/i17184.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo
2+
trait Bar:
3+
val foo : Int
4+
val f : Option[foo.type] = Some(foo)
5+
6+
def g : Boolean =
7+
f match
8+
case None => false
9+
case Some(_) => true

0 commit comments

Comments
 (0)