5 ms·
thats a very slippery slope. - (0 < 1) is a constant. - ((10 + 10)*15 > 0) is a constant. where do you draw the line in the type checker at working these
by octo_t 11y ago
thats a very slippery slope.
- (0 < 1) is a constant.
- ((10 + 10)*15 > 0) is a constant.
where do you draw the line in the type checker at working these things out?
- adriaanm 11y agoExactly. 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)} }
- pklausler 11y agoProbably somewhere before "if (halts(f,x))".
- lfowles 11y agoRelated to sibling comment, is the halting problem an issue if you just allow expressions without recursion/loops? Along the lines of constexpr in C++.