Skip to content

Fix #2198: Don't widen module singletons #2206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i2198.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Test {
val nil = scala.collection.immutable.Nil
def f(x: nil.type): Int = 3

f(scala.collection.immutable.Nil)
}