Aladdin - Scala Bugtracking
[#414] project: compiler priority: low category: missing feature
submitter assigned to status date submitted
Burak Martin won't fix 2005-04-06 11:29:08.0
subject empty case class constructor
code
case class Empty[a] extends IntMap[a];
case class Node[a](left: IntMap[a], keyVal: Pair[int, a], right: IntMap[a]) extends IntMap[a];
abstract class IntMap[a] {
        def lookup(key: int): a = this match {
                case Empty =>
                        error("clef inexistante")
                case _ =>
        };

};
what happened
IntMap.scala:5: polymorphic expression of type [a]()Empty[a] cannot be instantiated from expected type IntMap[a]\

                case Empty =>
                     ^
what expected The problem goes away if one writes Empty().

Shouldn't we treat Empty and Empty() the same?

The phase that handles empty argument list in constructors (which? Analyzer?) could also handle case class patterns that do not take parameters.

[back to overview]
Changes of this bug report
Martin  edited on  2006-03-30 18:01:09.0
It's a problem of pattern categorization. The typer first classifies patterns according to their form: If a pattern has arguments its a constructor pattern otherwise its a pattern constant. Note that the latest scalac gives a better error message: pending/pos/bug414.scala:5 error: stable identifier required, but Empty found. case Empty => ^