E4081#
The identifier is bound more than once in the same pattern.
It is not possible to bind to values into one identifier because they might have
different values. If you want to shadow the first identifier, you can use _
to
discard it.
错误示例:#
fn f(a : Int?, b : Int?) -> Unit {
match (a, b) {
(Some(a), Some(a)) => println("Some(\{a})")
// ^ Error: The identifier a is bound more than once in the same pattern.
_ => println("None")
}
}
建议#
Use a different name for the second identifier.
fn f(a : Int?, b : Int?) -> Unit {
match (a, b) {
(Some(a), Some(b)) => println("Some(\{a}), Some(\{b})")
_ => println("None")
}
}
If you want a shadow-like behavior here, you can explicitly discard the first
a
using _
:
fn f(a : Int?, b : Int?) -> Unit {
match (a, b) {
(Some(_), Some(a)) => println("Some(\{a})")
_ => println("None")
}
}