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

GADTs cause false positive asInstanceOf reports #378

Closed
erdeszt opened this issue Jun 11, 2020 · 1 comment
Closed

GADTs cause false positive asInstanceOf reports #378

erdeszt opened this issue Jun 11, 2020 · 1 comment

Comments

@erdeszt
Copy link
Contributor

erdeszt commented Jun 11, 2020

This code:

sealed trait MyGADT[T]
final case class VariantInt(value:    Int) extends MyGADT[Int]
final case class VariantString(value: String) extends MyGADT[String]

def doStuff[T](gadt: MyGADT[T]): T = {
  gadt match {
    case VariantInt(value)    => value
    case VariantString(value) => value
  }
}

Produces the following false positives:

[error] MyGADT.scala:7:34: [scapegoat] Use of asInstanceOf    
[error]   Use of asInstanceOf is considered a bad practice - consider using pattern matching instead.                                                            
[error]   value.asInstanceOf[T]                                                                                                                                  
[error]       case VariantInt(value)    => value
[error] MyGADT.scala:8:34: [scapegoat] Use of asInstanceOf    
[error]   Use of asInstanceOf is considered a bad practice - consider using pattern matching instead.                                                            
[error]   value.asInstanceOf[T]                                                                                                                                  
[error]       case VariantInt(value)    => value
mccartney added a commit to mccartney/scapegoat that referenced this issue Oct 3, 2020
mccartney added a commit that referenced this issue Oct 3, 2020
@mccartney
Copy link
Collaborator

I cannot reproduce using latest master - as demonstrated in a unit test added in #432.

@saeltz saeltz closed this as completed Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants