Skip to content

Another escape hatch for missing backtick in pattern lint #13120

@som-snytt

Description

@som-snytt

Reproduction steps

Scala version: 2.13.16

    @inline def matches[A](a: A)(pf: PartialFunction[A, Unit]): Boolean = pf.isDefinedAt(a)

    def sameTypeAndSameCaseClass = tp1 match {
      case tp1: TypeRef               => matches(tp2) { case tp2: TypeRef if isSameTypeRef(tp1, tp2) => }
    }

Problem

[warn] .../scala/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala:251:62: Name tp2 is already introduced in an enclosing scope as value tp2 at line 205. Did you intend to match it using backquoted `tp2`?
[warn]       case tp1: TypeRef               => matches(tp2) { case tp2: TypeRef if isSameTypeRef(tp1, tp2) => }
[warn]                                                              ^

It would be nice if the lint noticed that value tp2 is an input to the application, much as it recognizes

tp2 match { case tp2: TypeRef => }

where the selector expression is f(tp2) or just tp2 itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions