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

false positive VariableShadowing when use copy in map #573

Open
btomala opened this issue Oct 1, 2021 · 1 comment
Open

false positive VariableShadowing when use copy in map #573

btomala opened this issue Oct 1, 2021 · 1 comment

Comments

@btomala
Copy link

btomala commented Oct 1, 2021

Bellow code generate VariableShadowing warning.

[scapegoat] [VariableShadowing] Variable shadowing
[warn]   Variable shadowing is very useful, but can easily lead to nasty bugs in your code. Shadowed variables can be potentially confusing to other maintainers when the same name is adopted to have a new meaning in a nested scope.
[warn]   <artifact> val x$3: String = cat.copy$default$2
[warn]     Some(cat).map(_ => cat.copy(age = cat.age + 1))
[warn]                            ^
  final case class Cat(name: String, owner: String, age: Int)
  def grow(cat: Cat): Option[Cat] = {
    Some(cat).map(_ => cat.copy(age = cat.age + 1))
  }

What is important is that Cat has more than two fields and copy has to be done in map.

java: 11.0.12
scala: 2.13.6
sbt.version: 1.5.5
scapegoat: 1.4.10
sbt-scapegoat: 1.1.1

@btomala
Copy link
Author

btomala commented Mar 8, 2023

  private def test() = Vector(Vector(1, 23), Vector(2, 3, 5, 6)).collect(_.collect(_ == 5))

The above code where collect is inside of collect also generate false positive for variable shadowing

[scapegoat] [VariableShadowing] Variable shadowing
[error]   Variable shadowing is very useful, but can easily lead to nasty bugs in your code. Shadowed variables can be potentially confusing to other maintainers when the same name is adopted to have a new meaning in a nested scope.
[error]   <synthetic> val default: A1 => B1 = _
[error]   private def test() = Vector(Vector(1, 23), Vector(2, 3, 5, 6)).collect(_.collect(_ == 5))

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

2 participants