Skip to content

Commit

Permalink
Avoid over widening in SpaceEngine (#18252)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jul 20, 2023
2 parents 816bd5e + 6bea14b commit fd95c55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ object SpaceEngine {
if (arity > 0)
productSelectorTypes(resTp, unappSym.srcPos)
else {
val getTp = resTp.select(nme.get).finalResultType.widenTermRefExpr
val getTp = resTp.select(nme.get).finalResultType match
case tp: TermRef if !tp.isOverloaded =>
// Like widenTermRefExpr, except not recursively.
// For example, in i17184 widen Option[foo.type]#get
// to Option[foo.type] instead of Option[Int].
tp.underlying.widenExpr
case tp => tp
if (argLen == 1) getTp :: Nil
else productSelectorTypes(getTp, unappSym.srcPos)
}
Expand Down
9 changes: 9 additions & 0 deletions tests/patmat/i17184.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo
trait Bar:
val foo : Int
val f : Option[foo.type] = Some(foo)

def g : Boolean =
f match
case None => false
case Some(_) => true

0 comments on commit fd95c55

Please sign in to comment.