Skip to content

Inlined match statements should not fail on unreachable cases #8967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
letalvoj opened this issue May 12, 2020 · 1 comment · Fixed by #14871
Closed

Inlined match statements should not fail on unreachable cases #8967

letalvoj opened this issue May 12, 2020 · 1 comment · Fixed by #14871
Assignees
Milestone

Comments

@letalvoj
Copy link

letalvoj commented May 12, 2020

Minimized code

inline def aToB[T,A,B](t:T,b:B): T|B = t match {
  case _:A => b
  case _:T => t
}

@main def main() = aToB[Int, Double, String](1,"x")

Output

❌ this case is unreachable since type Int is not a subclass of class Double

Expectation

A warning? User of the inlined method would be hardly able to do anything about it if it came from a library.

Moreover, is a dead branch of match statement really worth a compile error? Non-exhaustive matches, which seem more serious to me, are just warnings now.

@letalvoj
Copy link
Author

I've just encountered it again. I want to check wheteher V is of SSHMsg and this feature prevents me from doing that.

    inline given productWriter[V:ClassTag](using m: Mirror.ProductOf[V]) as SSHWriter[V] = (ls:V, os:OutputStream) => {
        ls match {
            case msg:SSHMsg[_] => os.write(msg.magic)
            case _ =>
        }
        writeProduct[m.MirroredElemTypes](ls.asInstanceOf)(os)(0)
    }

Rewriting using if-statement as a workaround

        if (ls.isInstanceOf[SSHMsg[_]])
            os.write(ls.asInstanceOf[SSHMsg[_]].magic)

@odersky odersky assigned odersky and unassigned nicolasstucki Apr 6, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 7, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 7, 2022
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 25, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants