E0036#

警告名:block_label_shadowing

ブロックまたはループのラベルが、すでにスコープ内にあるラベルを隠しています。

ブロックとループのラベルは同じ名前空間を共有します。ネストしたブロックまたはループでラベル名を再利用すると、内側のラベルが外側のラベルを隠し、ラベル付き breakcontinue の対象が不明確になります。

break はブロックとループのどちらも対象にできますが、continue が対象にできるのはループだけです。そのため、ラベルの隠蔽によって意図とは異なる構造へ制御が移る可能性があります。ネストしたブロックとループのラベルには、互いに異なる説明的な名前を使用してください。

Erroneous example#

///|
fn has_positive(xs : Array[Int]) -> Bool {
  found~: {
    // Warning: The label name `found` shadows a label name that is already in scope.
    found~: for x in xs {
      if x > 0 {
        break found~
      }
    }
    false
  }
}

Suggestion#

ネストしたブロックとループには、互いに異なる説明的なラベル名を使用し、各制御フローの対象を明確にしてください。

///|
fn has_positive(xs : Array[Int]) -> Bool {
  found~: {
    search~: for x in xs {
      if x > 0 {
        break found~ true
      }
      continue search~
    }
    false
  }
}