Skip to content

false positive VariableShadowing when use copy in map #573

@btomala

Description

@btomala

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions