scala/bug

Compiler should not catch StackOverflowError

olafurpg opened this issue · 2 comments

While upgrading scalafix to 2.12.4 I observed a regression while inferring an implicit typeclass instance. The implicit resolved fine in 2.12.3, but not in 2.12.4. After spending a good part of my day trying to track down what caused the regression I noticed that a StackOverflowError is getting caught and reported under -Xlog-implicits

[info]  [E420] scalafix-cli/src/main/scala/scalafix/internal/cli/ArgParserImplicits.scala
[info]         shapeless.this.Strict.mkStrict is not a valid implicit value for shapeless.Strict[caseapp.core.HListParser.Aux[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("stackVerbosity")],Int] :: shapeless.HNil,Option[Int] :: shapeless.HNil,scala.collection.immutable.Nil.type :: shapeless.HNil,None.type :: shapeless.HNil,None.type :: shapeless.HNil,Some[caseapp.Hidden] :: shapeless.HNil,None.type :: shapeless.HNil,PT]] because:
[info]         hasMatchingSymbol reported error: exception during macro expansion:
[info]         java.lang.StackOverflowError
[info]         	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.typedConstructorPattern(PatternTypers.scala:61)
[info]         	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.typedConstructorPattern$(PatternTypers.scala:70)

Full output from -Xlog-implicits https://gist.github.com/olafurpg/715838db3776282939b5a30042cc2605#file-2-12-4-stackoverflow-txt-L859

I don't think the compiler should be catching fatal errors like this and optionally reporting them under a flag. A StackOverflowError should propagate immediately to the user, and that would have saved me a lot of time today.

Related issue: #10604 (comment)
PR upgrading scalafix to 2.12.4 scalacenter/scalafix#477 (comment)

The related issue in shapeless is milessabin/shapeless#776 and the underlying cause in scalac is #10552

Thanks @joroKr21 I will close this as a duplicate then.