Scala Programming Language
  1. Scala Programming Language
  2. SI-7385

Compiler crash during parsing because of `while` condition lacks parentheses

    Details

      Description

      Compile the following using Scala 2.10.1

      object Foo {
        while i<10 { () }
      }
      

      And you'll get a "nice" compiler crash during parsing.

      This is a regression wrt Scala 2.10.0. Indeed, the Scala 2.10.0 compiler correctly reports a syntax error for the above snippet.

      Below follows the full stack-trace as reported by the Scala 2.10.1 compiler:

      error: 
           while compiling: Main.scala
              during phase: parser
           library version: version 2.10.1
          compiler version: version 2.10.1
        reconstructed args: 
      
        last tree to typer: EmptyTree
                    symbol: null
         symbol definition: null
                       tpe: <notype>
             symbol owners: 
            context owners: package <root>
      
      == Enclosing template or block ==
      
      Template(
        // parents
        ValDef(
          private
          "_"
          <tpt>
          <empty>
        )
        {}
      )
      
      == Expanded type of tree ==
      
      <notype>
      
      uncaught exception during compilation: java.lang.UnsupportedOperationException
      error: java.lang.UnsupportedOperationException: Position.point on class scala.reflect.internal.util.NoPosition$
      	at scala.reflect.internal.util.Position.point(Position.scala:120)
      	at scala.reflect.internal.util.Position.endOrPoint(Position.scala:129)
      	at scala.tools.nsc.ast.parser.TreeBuilder.makeWhile(TreeBuilder.scala:255)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.parseWhile$1(Parsers.scala:1339)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.expr0(Parsers.scala:1342)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.expr(Parsers.scala:1285)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStatSeq$1.apply(Parsers.scala:2971)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStatSeq$1.apply(Parsers.scala:2966)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:428)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateStatSeq(Parsers.scala:2966)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateBody(Parsers.scala:2846)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateBodyOpt(Parsers.scala:2853)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateOpt(Parsers.scala:2812)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.objectDef(Parsers.scala:2732)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.tmplDef(Parsers.scala:2670)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.topLevelTmplDef(Parsers.scala:2651)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStatSeq$2.apply(Parsers.scala:2937)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStatSeq$2.apply(Parsers.scala:2937)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.joinComment(Parsers.scala:683)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.topStatSeq(Parsers.scala:2937)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.topstats$1(Parsers.scala:3132)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.apply(Parsers.scala:3138)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.apply(Parsers.scala:3102)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:428)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.compilationUnit(Parsers.scala:3102)
      	at scala.tools.nsc.ast.parser.Parsers$SourceFileParser$$anonfun$parseStartRule$1.apply(Parsers.scala:141)
      	at scala.tools.nsc.ast.parser.Parsers$SourceFileParser$$anonfun$parseStartRule$1.apply(Parsers.scala:141)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.parse(Parsers.scala:313)
      	at scala.tools.nsc.ast.parser.Parsers$UnitParser.smartParse(Parsers.scala:242)
      	at scala.tools.nsc.ast.parser.SyntaxAnalyzer$ParserPhase.apply(SyntaxAnalyzer.scala:29)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:430)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1552)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1661)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:79)
      	at scala.tools.nsc.Driver.process(Driver.scala:54)
      	at scala.tools.nsc.Driver.main(Driver.scala:67)
      	at scala.tools.nsc.Main.main(Main.scala)
      
      Exception in thread "main" java.lang.UnsupportedOperationException: Position.point on class scala.reflect.internal.util.NoPosition$
      	at scala.reflect.internal.util.Position.point(Position.scala:120)
      	at scala.reflect.internal.util.Position.endOrPoint(Position.scala:129)
      	at scala.tools.nsc.ast.parser.TreeBuilder.makeWhile(TreeBuilder.scala:255)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.parseWhile$1(Parsers.scala:1339)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.expr0(Parsers.scala:1342)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.expr(Parsers.scala:1285)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStatSeq$1.apply(Parsers.scala:2971)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$templateStatSeq$1.apply(Parsers.scala:2966)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:428)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateStatSeq(Parsers.scala:2966)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateBody(Parsers.scala:2846)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateBodyOpt(Parsers.scala:2853)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.templateOpt(Parsers.scala:2812)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.objectDef(Parsers.scala:2732)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.tmplDef(Parsers.scala:2670)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.topLevelTmplDef(Parsers.scala:2651)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStatSeq$2.apply(Parsers.scala:2937)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$topStatSeq$2.apply(Parsers.scala:2937)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.joinComment(Parsers.scala:683)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.topStatSeq(Parsers.scala:2937)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.topstats$1(Parsers.scala:3132)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.apply(Parsers.scala:3138)
      	at scala.tools.nsc.ast.parser.Parsers$Parser$$anonfun$compilationUnit$1.apply(Parsers.scala:3102)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.checkNoEscapingPlaceholders(Parsers.scala:428)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.compilationUnit(Parsers.scala:3102)
      	at scala.tools.nsc.ast.parser.Parsers$SourceFileParser$$anonfun$parseStartRule$1.apply(Parsers.scala:141)
      	at scala.tools.nsc.ast.parser.Parsers$SourceFileParser$$anonfun$parseStartRule$1.apply(Parsers.scala:141)
      	at scala.tools.nsc.ast.parser.Parsers$Parser.parse(Parsers.scala:313)
      	at scala.tools.nsc.ast.parser.Parsers$UnitParser.smartParse(Parsers.scala:242)
      	at scala.tools.nsc.ast.parser.SyntaxAnalyzer$ParserPhase.apply(SyntaxAnalyzer.scala:29)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:430)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1552)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1661)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:79)
      	at scala.tools.nsc.Driver.process(Driver.scala:54)
      	at scala.tools.nsc.Driver.main(Driver.scala:67)
      	at scala.tools.nsc.Main.main(Main.scala)
      

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Regressed in 80a814d82c courtesy of a certain J. Iry.

          Show
          Paul Phillips added a comment - Regressed in 80a814d82c courtesy of a certain J. Iry.
          Hide
          Paul Phillips added a comment - - edited
          Show
          Paul Phillips added a comment - - edited https://github.com/scala/scala/pull/2472
          Hide
          Paul Phillips added a comment -

          5c77e01

          Show
          Paul Phillips added a comment - 5c77e01

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Mirco Dotta
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development