aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Namer.scala6
-rw-r--r--tests/pos/i2198.scala6
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala
index ce2030c01..b436b36b0 100644
--- a/compiler/src/dotty/tools/dotc/typer/Namer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala
@@ -1043,9 +1043,11 @@ class Namer { typer: Typer =>
def isInline = sym.is(FinalOrInline, butNot = Method | Mutable)
// Widen rhs type and approximate `|' but keep ConstantTypes if
- // definition is inline (i.e. final in Scala2).
+ // definition is inline (i.e. final in Scala2) and keep module singleton types
+ // instead of widening to the underlying module class types.
def widenRhs(tp: Type): Type = tp.widenTermRefExpr match {
- case tp: ConstantType if isInline => tp
+ case ctp: ConstantType if isInline => ctp
+ case ref: TypeRef if ref.symbol.is(ModuleClass) => tp
case _ => ctx.harmonizeUnion(tp.widen)
}
diff --git a/tests/pos/i2198.scala b/tests/pos/i2198.scala
new file mode 100644
index 000000000..62ae7e8b5
--- /dev/null
+++ b/tests/pos/i2198.scala
@@ -0,0 +1,6 @@
+object Test {
+ val nil = scala.collection.immutable.Nil
+ def f(x: nil.type): Int = 3
+
+ f(scala.collection.immutable.Nil)
+}