Aladdin - Scala Bugtracking
[#945] project: compiler priority: low category: bug
submitter assigned to status date submitted
Nikolay Burak open 2007-02-11 17:46:43.0
subject [contrib #318] Bad unapply return type crashes compiler
code
// Crashes compiler 2.3.3
object IllegalMatch {

    case class C(x: AnyRef)

    def unapply(x: AnyRef): C = // should be Option[C]
    {
        error("not implemented")
    }

    null match {
        case IllegalMatch(C(_)) => ()
    }
}
what happened
Exception in thread "main" java.lang.IllegalArgumentException: class C in not in {boolean, option, some}
	at scala.tools.nsc.symtab.Definitions$definitions$.unapplyTypeListFromReturnType(Definitions.scala:206)
	at scala.tools.nsc.symtab.Definitions$definitions$.unapplyTypeList(Definitions.scala:184)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply(Typers.scala:1497)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:2081)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPattern(Typers.scala:2293)
	at scala.tools.nsc.typechecker.Typers$Typer.typedCase(Typers.scala:1178)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$42.apply(Typers.scala:1201)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$42.apply(Typers.scala:1200)
	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:1200)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1976)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2265)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:1296)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.scala:1317)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.scala:1317)
	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:1317)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:920)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:841)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1842)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2265)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$0(Typers.scala:1296)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.scala:1317)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$51.apply(Typers.scala:1317)
	at scala.List$.loop$0(List.scala:243)
	at scala.List$.mapConserve(List.scala:260)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:1317)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1835)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2232)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2265)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$1.apply(Analyzer.scala:38)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:230)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:219)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$2.apply(Global.scala:219)
	at scala.Iterator$class.foreach(Iterator.scala:377)
	at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:244)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:219)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:484)
	at scala.tools.nsc.Global$Run.compile(Global.scala:555)
	at scala.tools.nsc.Main$.process(Main.scala:59)
	at scala.tools.nsc.Main$.main(Main.scala:81)
	at scala.tools.nsc.Main.main(Main.scala)
what expected Compiler error report with line number, e.g. unapply return type C in not in {boolean, option} A minor note:- The compile is successful if the return type of unapply is Some[C], but crashes if the return type is Nothing. Should the language spec section 8.1.7 say "conforms to" Option instead of "is", and so also support Nothing, or should the spec mention support for Some, or should the compile fail when the return type is Some (but requiring Option likely throws away performance)?
[back to overview]
Changes of this bug report
Nikolay  edited on  2007-02-11 17:47:22.0
contribution #318
Martin  edited on  2007-02-28 00:03:54.0
Reassigned to Burak. Burak, I think the stuff like `unapplyTypeList' in definitions has to go in the typer. One cannot just throw an IllegalArgumentException, because how do you know that user input is correct? On the other hand, because the unapply stuff is rather complicated and the typer is already too big to be comfortable, maybe move all this stuff into a helper module like variances, eta expand, or infer.