E4217#
Compiler diagnostic name: lexscan_guard_not_supported.
lexscan case 不支持守卫条件。
扫描器会先根据正则模式选择 case,再执行 case 函数体。守卫会使这个选择依赖任意表达式。
错误示例#
///|
pub fn classify(input : String, allow : Bool) -> String {
lexscan input {
re"^[a-z]+$" if allow => "word"
_ => "other"
}
}
建议#
将额外条件移入被选中的 case 函数体。
///|
pub fn classify(input : String, allow : Bool) -> String {
lexscan input {
re"^[a-z]+$" => if allow { "word" } else { "other" }
_ => "other"
}
}