Uploaded image for project: 'SonarSlang'
  1. SonarSlang
  2. SONARSLANG-514

[Scala] S1871 FPs with complex pattern matching

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 1.9
    • Component/s: Scala
    • Labels:
      None

      Description

      Related to SONARSLANG-351 and pattern matching that can:

      • shadow an external variable which may be used in other case blocks
      • cast to a different type (with the same name), which would make refactoring more difficult - this should be confirmed whether it should be treated or not
        // False positives that haven't been fixed by SONARSLANG-351
        def knownIssues(cond: Any, x : Int) : String = {
          cond match {
            case 4 =>
              val a: String = "" + x + 1
              a
            case (Some(x: Int), y) => // FP, shadowing the variable
              val a: String = "" + x + 1 // Noncompliant
              a
            case (1 | 2) :: x :: tail => // FP, shadowing the variable
              val a: String = "" + x + 1 // Noncompliant
              a
            case x: Long if x == 0 => // FP, shadowing the variable
              val a: String = "" + x + 1 // Noncompliant
              a
            case _ =>
              "1"
          }
        }
      

      Peach examples:

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              andrei.epure Andrei Epure
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: