Skip to content

Commit 80f9b6d

Browse files
authored
Merge pull request #2206 from dotty-staging/fix-#2198
Fix #2198: Don't widen module singletons
2 parents 7294180 + e2639e0 commit 80f9b6d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,11 @@ class Namer { typer: Typer =>
10431043
def isInline = sym.is(FinalOrInline, butNot = Method | Mutable)
10441044

10451045
// Widen rhs type and approximate `|' but keep ConstantTypes if
1046-
// definition is inline (i.e. final in Scala2).
1046+
// definition is inline (i.e. final in Scala2) and keep module singleton types
1047+
// instead of widening to the underlying module class types.
10471048
def widenRhs(tp: Type): Type = tp.widenTermRefExpr match {
1048-
case tp: ConstantType if isInline => tp
1049+
case ctp: ConstantType if isInline => ctp
1050+
case ref: TypeRef if ref.symbol.is(ModuleClass) => tp
10491051
case _ => ctx.harmonizeUnion(tp.widen)
10501052
}
10511053

tests/pos/i2198.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
val nil = scala.collection.immutable.Nil
3+
def f(x: nil.type): Int = 3
4+
5+
f(scala.collection.immutable.Nil)
6+
}

0 commit comments

Comments
 (0)