Skip to content
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

Probably a false positive warning for type tests #16259

Closed
WojciechMazur opened this issue Oct 28, 2022 · 3 comments
Closed

Probably a false positive warning for type tests #16259

WojciechMazur opened this issue Oct 28, 2022 · 3 comments
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore stat:needs spec

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Oct 28, 2022

Type test for locally defined classes (eg. within method) ends up with a warning. Not sure if it's a false negative positive introduced via regression or an improvement.

Compiler version

3.2.1

Minimized code

@main def Test = {
  class A(private val x: Int) {
    override def equals(that: Any): Boolean = that match {
      case that: A => this.x == that.x
      case _       => false
    }
  }
}

Output

Compiling project (Scala 3.2.1, JVM)
[warn] ./sandbox/src/main/scala/Test.scala:5:12: the type test for A cannot be checked at runtime
[warn]       case that: A => this.x == that.x

Expectation

@SethTisue
Copy link
Member

Seems like a regression to me. I see no reason the type test couldn't be performed.

Nitpick: we would refer to this as a "false positive", not a "false negative" — as per https://en.wikipedia.org/wiki/False_positives_and_false_negatives, it isn't about whether something good or something bad is being signaled; it's about whether a signal is present or absent. Here something (a warning) is present when it shouldn't be, hence "false positive" — despite the warnings being about something bad.

@SethTisue SethTisue changed the title Probably a false negative warning for type tests Probably a false positive warning for type tests Oct 28, 2022
@dwijnand
Copy link
Member

It's not a regression, it's right. See #4812 and #15134.

@dwijnand dwijnand closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2022
@SethTisue
Copy link
Member

TIL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore stat:needs spec
Projects
None yet
Development

No branches or pull requests

3 participants