E0050

E0050#

Local method shadows upstream method.

对于不属于当前包的类型,可以定义方法。当方法名称与现有方法相同时,可能会导致无法确定所引用的具体方法。

错误示例#

///|
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")
}