This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why is type checking not transparent wrt. type alias?

No replies
Eugene Vigdorchik
Joined: 2010-03-30,
User offline. Last seen 35 weeks 3 days ago.

Hello,
I'm struggling to understand why the following session produces
compilation error:

scala> type Nil = Nil.type
defined type alias Nil

scala> val n :Nil = Nil
:6: error: type mismatch;
found : n.type (with underlying type Nil)
required: Nil
val n :Nil = Nil
^

However if I don't use type alias, it works no problem:

scala> val n:Nil.type = Nil
n: scala.collection.immutable.Nil.type = List()

Thank you in advance for your help,
Eugene.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland