E0050

E0050#

Local method shadows upstream method.

Methods can be defined for types that does not belong to the current package. When having the same name as the existing ones, it can lead to confusion about which method is being referenced.

错误示例#

///|
fn Int::abs(i : Int) -> Int {
  if i > 0 {
    i
  } else {
    -i
  }
}

///|
test {
  inspect((-1).abs(), content="1")
}

建议#

Use distince names for local methods to make the code’s intent clear.

///|
fn Int::local_abs(i : Int) -> Int {
  if i > 0 {
    i
  } else {
    -i
  }
}

///|
test {
  inspect((-1).local_abs(), content="1")
}