Compiler crashes instead of reporting an error

42 views
Skip to first unread message

Georgi Jojgov

unread,
Nov 15, 2016, 9:11:47 AM11/15/16
to scala-internals
Hi,

The code below crashes the 2.11.8 compiler instead of producing a type mismatch error message (see attachments):

object Crasher {
  trait
Handler {
   
def onPush(): Unit
   
def onUpstreamFinish() : Unit
 
}

 
def setHandler(handler: Handler): Unit = {}

  setHandler
(new Handler {
   
override def onPush(): Unit = {
     
// changing 100L to 100 avoids the crash
     
(0 until 100L) foreach {_ => ()}
   
}


   
@throws(classOf[Exception])
   
def onUpstreamFinish(): Unit = {}
 
})
}

The top of error stack trace is:

java.lang.NullPointerException
 at scala
.tools.nsc.typechecker.Typers$Typer.typedAnnotation(Typers.scala:3669)
 at scala
.tools.nsc.typechecker.Namers$Namer$$anonfun$23$$anonfun$apply$17$$anonfun$apply$18.apply(Namers.scala:1504)
 at scala
.tools.nsc.typechecker.Namers$Namer$$anonfun$23$$anonfun$apply$17$$anonfun$apply$18.apply(Namers.scala:1504)
 at scala
.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:235)
 at scala
.tools.nsc.typechecker.Namers$Namer$$anonfun$23$$anonfun$apply$17.apply(Namers.scala:1504)
 at scala
.tools.nsc.typechecker.Namers$Namer$$anonfun$23$$anonfun$apply$17.apply(Namers.scala:1504)
 at scala
.reflect.internal.AnnotationInfos$LazyAnnotationInfo.forcedInfo$lzycompute(AnnotationInfos.scala:212)
 at scala
.reflect.internal.AnnotationInfos$LazyAnnotationInfo.forcedInfo(AnnotationInfos.scala:212)
 at scala
.reflect.internal.AnnotationInfos$LazyAnnotationInfo.completeInfo(AnnotationInfos.scala:225)
 at scala
.tools.nsc.typechecker.Typers$Typer$$anonfun$typedDefDef$2.apply(Typers.scala:2185)
 at scala
.tools.nsc.typechecker.Typers$Typer$$anonfun$typedDefDef$2.apply(Typers.scala:2185)
 at scala
.collection.immutable.List.map(List.scala:273)
 at scala
.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:2185)
 at scala
.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5308)
 at scala
.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5359)
 at scala
.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
 at scala
.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
 at scala
.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
 at scala
.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
 at scala
.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5452)
 at scala
.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:3047)
 at scala
.tools.nsc.typechecker.Typers$Typer$$anonfun$65.apply(Typers.scala:3151)
 at scala
.tools.nsc.typechecker.Typers$Typer$$anonfun$65.apply(Typers.scala:3151)


The expected compile error is exposed for example by commenting out the @throws annotation:

[error] <....>/Crasher.scala:12: type mismatch;
[error]  found   : Long(100L)
[error]  required: Int
[error]       (0 until 100L) foreach {_ => ()}
[error]                ^
[error] one error found

Removing the error by changing 

(0 until 100L) foreach {_ => ()}

to

(0 until 100) foreach {_ => ()}

results in successful compile.


Is this a known issue or should I file a bug?

Georgi




bug_report.zip

Seth Tisue

unread,
Nov 16, 2016, 4:31:14 PM11/16/16
to scala-i...@googlegroups.com
The 2.12.0 compiler doesn’t crash on this, so I wouldn’t bother opening a JIRA ticket on it.
Reply all
Reply to author
Forward
0 new messages