Open noresttherein opened 2 years ago
Since 2.12.7. -Vtyper
in 2.13. It's always been a bit finicky.
Edit: 2.12.7 includes 2.13.0-RC1 backports.
By finicky, I mean duplicates https://github.com/scala/bug/issues/12601 which is the same stack trace, but I don't remember the disposition, so let's leave this open until there is some clarity.
I don't want to appear entitled, but would it be possible to catch errors in the compiler and provide additional information about the location in the code it was looking at when it was caught? Stack overflows in the compiler can be super tricky to debug, it often takes me up to a week to find the cause, especially when introduced by a larger refactor. As the compiler jumps around quite a bit, not always the last location printed by a debug option gives a good idea about where the problem is, let alone what it is.
For example, I personally use something like:
rethrow { persistence.save(entity) } (s"Failed to save $entity.")
def rethrow[T](block: => T)(msg: => String) :T =
try { block } catch {
case e :Throwable =>
e.addSuppressed(new RethrowContext(msg))
throw e
}
class RethrowContext(msg: =>String) extends Exception {
override lazy val getMessage = msg
}
It's not a huge effert to pepper the code with such rethrows, at least in places liable to cause problems - TypeComparers
would be my first candidate. This way, an exception printed to the console with any standard formatter will include the information from higher on the stack. It really would be a huge quality of life feature from my point of view.
By "larger refactor", I guess you mean that you refactor your code and the (maybe buggy compiler) symptom changes so it's hard to know how to get your code to compile nicely again?
For error context there is https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/Global.scala#L1080
It doesn't always know when to discard error context as it tries a series of adaptations, for example. (Also, not an expert.)
I feel really stupid, as I see I actually reported it previously myself and have no recollection of it. I don't know why it didn't show in my search with a stack trace element? I swear I started with it in hope that maybe there is some info on it. I must have searched with the default is:open
I guess.
And yes, especially things like adding/removing a type parameter to a whole class hierarchy are risky in my experience.
And regarding the error context, isn't the method only called when the compiler actually reports an error, rather than terminates by throwing an Error
?
and have no recollection of it.
That seems totally normal to me. Possibly, I mean "normalized".
I wonder if there are certain refactorings that play havoc with incremental compilation.
I think abort
will try to supplement with typer state; it was originally a simpler try-catch thing, IIRC, but I see now it zig-zags through the reporter for the current run (which does all the buffered messaging and warning config).
On context, there have been efforts around typing, but less around crashing cleanly. Maybe Scala 4 will be the compiler with opinionated crashes.
About improving error reporting when the compiler crashes: fwiw, we're trying to improve that in Scala 3 over at https://github.com/lampepfl/dotty/pull/16593 . It's an area where pull requests remain welcome in Scala 2 as well.
So, should this one stay open or not? I'm confused by the history here.
The linked ticket had 2 cases: the NPE was transferred to zinc; the assert duplicated this ticket.
I vote leave open for either fix the assertion or improve the crash output.
Reproduction steps
Scala version: 2.13.10
Problem
When compiling with
-Ytyper-debug
: