4 ms·
Exactly. The type checker does track constants (`false` internally has type `Boolean(false)`), but it won't drop `if` branches. That happens later, as you can s
by adriaanm 11y ago
Exactly. The type checker does track constants (`false` internally has type `Boolean(false)`), but it won't drop `if` branches. That happens later, as you can see in the (abridged) output of `scalac -Xprint:all -Xprint-types`:
[[syntax trees at end of typer]] // constif.scala
class ConstIf extends scala.AnyRef {
def m: Any = if (false{Boolean(false)})
23{Int(23)}
else
null{Null(null)}{Any}
}
[[syntax trees at end of refchecks]] // constif.scala
class ConstIf extends scala.AnyRef {
def m: Any = null{Null(null)}
}