-->

Scalac hanging on phase typer of RegexParser

2019-05-20 08:00发布

问题:

I have a scala program which among other things has a parser-combinator. This is done by extending scala.util.parsing.combinator.RegexParsers. I had developed it using Scala 2.10 and all was working fine.

Yesterday I upgraded my system to Scala 2.11.4, together with IntelliJ 14.02 (not that it matters).

However, whenever I try to compile this program now, scalac hangs during this phase:

scalac: phase typer on MyParser.scala

I changed absolutely nothing to this code, I can't understand why it is hanging or from where I should start. IntelliJ had a warning about postfix operators for parser expressions like constants_def? or structure_def*, where the ? and * follow the token, and I added this line, because of the SIP: Language Modularization Features:

import scala.language.postfixOps

It didn't really have any effect and the problem is still the same.

How can I troubleshoot what is going on? I can't figure out from where to start understanding why the phase typer is just hanging indefinitely.

回答1:

It looks like a workaround is to add an explicit type:

def da_gd : Parser[Expression with TimedCondition] =
  pref_timed_gd | da_gd_conjunction |
  (empty_temporal: Parser[Expression with TimedCondition])

A stack dump shows that it's figuring out the type of the expr, and -Ytyper-debug shows the vicinity.

Since nothing good happens after midnight, I'll stop there.