`scalac`'s -print option

I read that scalac has a -print option that “prints program with Scala-specific features removed”, as stated in the scalac options for Scala 2.

I then checked the lookup table, and it says that the -print flag exists in 3.3.x

But when I tried scalac -print src/Test.scala (I’m on version 3.3.5 and Test.scala is a simple test file), I get the output:

bad option '-print' was ignored
1 warning found

Trying --print, -print:true and --print:true leads to the same result.

Is the option removed? Or am I doing something wrong?

Thanks in advance!

TIL in Scala 2, --print is an alias of sorts for -Vprint:cleanup, and is apparently intended to provide a “late” view of the compiled code, which explains what is meant by “Scala-specific features removed”.

Scala 3 also supports -Vprint:typer, where you choose a “phase” to print at.

The list of phases is shown by -Vphases. The name can be a prefix, so that -Vprint:t prints at phases beginning with “t”.

In Scala 2, -Vprint without a phase name defaults to typer. It warns if your prefix selects multiple phases or none.

Scala 3 is less friendly about option parsing. It has no cleanup phase, so if you ask for it, the option is silently ignored. If you omit the name, it will consume the next argument instead.

There is a beautiful PR to correct some of these shortcomings.

-help (or -V, -W, -X) is the best source of information about options.

2 Likes

Thank you!

After some experimenting, I found -Vprint:erasure the best for what I want.

1 Like