E0050#
Warning name: method_shadowing
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.
Erroneous example#
///|
fn Int::abs(i : Int) -> Int {
if i > 0 {
i
} else {
-i
}
}
///|
test {
inspect((-1).abs(), content="1")
}
Suggestion#
Use distinct 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")
}