Aladdin - Scala Bugtracking
[#548] project: compiler priority: low category: bug
submitter assigned to status date submitted
Iulian _ fixed 2006-03-14 17:07:58.0
subject parser crash for value definition inside for comprehensions
code
abstract class Tree;
case class SList(xs: List[Tree]) extends Tree;
case class SIdent(s: String) extends Tree;

object Main {
  val t: Tree = SList(SIdent("define") :: SIdent("a") :: SIdent("b") :: Nil);
  val ts = t :: t :: Nil;

  for (val SList(ident :: a :: Nil) <- ts; 
       val SIdent(name) = ident) // boom!
    ();
}
what happened
Exception in thread "main" scala.MatchError: SList($colon$colon((ident @ _), $colon$colon((a @ _), Nil)))
        at scala.tools.nsc.ast.parser.TreeBuilder.makeValue$0(TreeBuilder.scala:244)
        at scala.tools.nsc.ast.parser.TreeBuilder$$anonfun$6.apply(TreeBuilder.scala:269)
        at scala.tools.nsc.ast.parser.TreeBuilder$$anonfun$6.apply(TreeBuilder.scala:269)
        at scala.List.map(List.scala:665)
        at scala.tools.nsc.ast.parser.TreeBuilder.makeFor(TreeBuilder.scala:269)
        at scala.tools.nsc.ast.parser.TreeBuilder.makeFor(TreeBuilder.scala:281)
        at scala.tools.nsc.ast.parser.Parsers$Parser.expr(Parsers.scala:691)
        at scala.tools.nsc.ast.parser.Parsers$Parser.expr(Parsers.scala:631)
        at scala.tools.nsc.ast.parser.Parsers$Parser.templateStatSeq(Parsers.scala:1747)
        at scala.tools.nsc.ast.parser.Parsers$Parser.templateBody(Parsers.scala:1674)
        at scala.tools.nsc.ast.parser.Parsers$Parser.classTemplate(Parsers.scala:1662)
        at scala.tools.nsc.ast.parser.Parsers$Parser.objectDef(Parsers.scala:1618)
        at scala.tools.nsc.ast.parser.Parsers$Parser.tmplDef(Parsers.scala:1587)
        at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$20.apply(Parsers.scala:1725)
        at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$20.apply(Parsers.scala:1725)
        at scala.tools.nsc.ast.parser.Parsers$Parser.joinComment(Parsers.scala:186)
        at scala.tools.nsc.ast.parser.Parsers$Parser.topStatSeq(Parsers.scala:1725)
        at scala.tools.nsc.ast.parser.Parsers$Parser.compilationUnit(Parsers.scala:1878)
        at scala.tools.nsc.ast.parser.Parsers$Parser.parse(Parsers.scala:67)
        at scala.tools.nsc.ast.parser.SyntaxAnalyzer$ParserPhase.apply(SyntaxAnalyzer.scala:16)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:208)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:197)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:197)
        at scala.Iterator$class.foreach(Iterator.scala:277)
        at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:216)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:197)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:422)
        at scala.tools.nsc.Global$Run.compile(Global.scala:480)
        at scala.tools.nsc.Main$.process(Main.scala:60)
        at scala.tools.nsc.Main$.main(Main.scala:80)
        at scala.tools.nsc.Main.main(Main.scala)
what expected to work... or an error m3ssage if not supposed to.
[back to overview]
Changes of this bug report
Burak  edited on  2006-03-15 10:44:09.0
fixed. is supposed to work, mistake was in the hyper-desugarizing makeFor code. A makeBind(pat) ensures that result of pat is bound to a variable, unfortunately, this happens *after* the first code point where the variable is needed and tried to be captured by makeValue.