Aladdin - Scala Bugtracking
[#960] project: compiler priority: low category: bug
submitter assigned to status date submitted
Iulian Martin fixed 2007-02-22 09:23:00.0
subject MatchError in the typechecker for double-def unnaply
code
sealed abstract class List[+a]
private case object Nil extends List[Nothing]
private final case class Cons[+a](head: a, tail: List[a])
extends List[a]

object List {
  def unapply[a](xs: List[a]): Option[(a, List[a])] = xs match {
    case Nil => None
    case Cons(x, xs) => Some(x, xs)
  }

  def unapply[a](xs: List[a]): Option[Null] = xs match {
    case Nil => Some(null)
    case Cons(_, _) => None
  }

  def foo[a](xs: List[a])  = xs match {
    case List(x, xs) => 7
  }
}
what happened
Removing def 'foo' makes the crash go away, and an error message is printed.

Exception in thread "main" scala.MatchError: [a](List[a])scala.Option[scala.Null]  [a](List[a])scala.Option\
[{a, List[a]}]
        at scala.tools.nsc.typechecker.Typers$Typer.freshArgType$0(Typers.scala:1514)
        at scala.tools.nsc.typechecker.Typers$Typer.typedApply(Typers.scala:1521)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2202)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2353)
        at scala.tools.nsc.typechecker.Typers$Typer.typedPattern(Typers.scala:2414)
        at scala.tools.nsc.typechecker.Typers$Typer.typedCase(Typers.scala:1185)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$45.apply(Typers.scala:1208)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$45.apply(Typers.scala:1207)
        at scala.List$.loop$0(List.scala:243)
        at scala.List$.mapConserve(List.scala:260)
        at scala.tools.nsc.typechecker.Typers$Typer.typedCases(Typers.scala:1207)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2080)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2353)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2397)
        at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:2429)
        at scala.tools.nsc.typechecker.Namers$Namer.methodSig(Namers.scala:524)
        at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:598)
        at scala.tools.nsc.typechecker.Namers$Namer$$anon$0.complete(Namers.scala:336)
        at scala.tools.nsc.symtab.Types$LazyPolyType.complete(Types.scala:1295)
        at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:397)
        at scala.tools.nsc.symtab.Symbols$Symbol.initialize(Symbols.scala:505)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1916)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2353)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2386)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:1304)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$54.apply(Typers.scala:1327)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$54.apply(Typers.scala:1327)
        at scala.List$.loop$0(List.scala:243)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1327)
        at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:947)
        at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:860)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1928)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2353)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2386)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:1304)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$54.apply(Typers.scala:1327)
        at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$54.apply(Typers.scala:1327)
        at scala.List$.loop$0(List.scala:243)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.List$.loop$0(List.scala:247)
        at scala.List$.mapConserve(List.scala:260)
        at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1327)
        at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1921)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2353)
        at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2386)
        at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$1.apply(Analyzer.scala:38)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:231)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:220)
        at scala.Iterator$class.foreach(Iterator.scala:379)
        at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:244)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:220)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:488)
        at scala.tools.nsc.Global$Run.compile(Global.scala:559)
        at scala.tools.nsc.Main$.process(Main.scala:57)
        at scala.tools.nsc.Main$.main(Main.scala:79)
        at scala.tools.nsc.Main.main(Main.scala)
what expected
[back to overview]
Changes of this bug report
Martin  edited on  2007-02-27 23:54:47.0