E4101#
管道运算符右侧不支持该表达式。
该错误发生在管道运算符右侧的表达式不是一个支持的形式。管道运算符允许您以更易读的方式链式调用函数,但它的右侧只支持特定的形式。
管道运算符右侧允许以下形式:
一个标识符(函数名)
一个普通的函数应用(但不是方法调用)
构造函数名
构造函数应用
错误示例#
type T Int
fn m(self: T, x: Int) -> Unit {
println(self._ + x)
}
pub fn f(t: T, x: Int) -> Unit {
x |> fn(x: Int) { println(x)}
// ^^^^^^^^^^^^^^^^^^^^^^^^ Error: Unsupported expression after the pipe operator.
x |> t.m()
// ^^^^ Error: Unsupported expression after the pipe operator.
}
建议#
要修复此错误,您可以将无效的管道表达式改为普通的函数或方法应用。
type T Int
fn m(self: T, x: Int) -> Unit {
println(self._ + x)
}
pub fn f(t: T, x: Int) -> Unit {
fn(x: Int) { println(x)}(x)
t.m(x)
}