scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.86k stars 1.06k forks source link

Possibly spurious warning on type test #12691

Closed japgolly closed 3 years ago

japgolly commented 3 years ago

Compiler version

3.0.0

Minimized code

sealed trait Action[Page]
case class Renderer[Page, Props]() extends Action[Page]
sealed trait Redirect[Page] extends Action[Page]

final class RouterLogic[Page, Props] {

  def hmm1(a: Action[Page]): Int =
    a match {
      case r: Renderer[Page, Props] => 1
      case _                        => 2
    }

  def hmm2(a: Action[Page]): Int =
    a match {
      case r: Redirect[Page] => 2
      case _                 => 1
    }
}

Output

[warn] 9 |      case r: Renderer[Page, Props] => 1
[warn]   |           ^^^^^^^^^^^^^^^^^^^^^^^^
[warn]   |      the type test for Renderer[Page, Props] cannot be checked at runtime
[warn] one warning found

Expectation

No warnings. (Scala 2.13.6 emits no warnings.)

japgolly commented 3 years ago

Actually, staring at this minimisation maybe the warning is correct and it's Scala 2.13 that's missing a warning.

Action[Page] doesn't have anything to say about the bounds of Props in Renderer[Page, Props]. Hmmmm.

Pls confirm? I think I need to inverse and move this issue over to Scala 2 land.

LPTK commented 3 years ago

Yes, obviously it could match Renderer[Page, p] for any p. There is no reason it should be the Props defined outside. Don't hold your breath for Scala 2 to fix this, though 😛

japgolly commented 3 years ago

Yeah. Thanks for the confirmation @LPTK :grinning: In to the Scala 2 backlog abyss it goes!

som-snytt commented 3 years ago

Scala 2 has received a bunch of improvements around pattern checks. This will be on the top of pile where someone might notice it.

japgolly commented 3 years ago

Fantastic! Very glad to hear that Scala 2 will keep getting love and care for a while yet :grin: