lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

Lost values should give a warning #241

Closed oliverlevay closed 1 year ago

oliverlevay commented 3 years ago
case class KeyControl(up: String, left: String, down: String, right: String):
  def direction(key: String): (Int, Int) =
    if (key == left) then (-1, 0)
    if (key == right) then (1, 0)
    if (key == up) then (0, -1)
    if (key == down) then (0, 1)
    else (0, 0)

This code has lost values that are unreachable. It would be awesome if this fact was warned about to the developer.

som-snytt commented 3 years ago

It will try to warn about non-side-effecting expressions:

10 |    if (key == left) then 0
   |                          ^
   |                          A pure expression does nothing in statement position; you may be omitting necessary parentheses

The issue seems to be that tuple construction is not detected as "pure (for purposes of error reporting)".

Is that a bug or a feature request?