E4101#
Unsupported expression after the pipe operator.
This error occurs when the expression after the pipe operator (|>) is not in a
supported form. The pipe operator allows you to chain function calls in a more
readable way, but only supports specific forms on its right-hand side.
The following forms are allowed after the pipe operator:
A single identifier (function name)
A regular function application (but not method calls)
A constructor name
A constructor application
Erroneous example#
///|
pub struct T(Int)
///|
pub fn make(x : Int) -> T {
T(x)
}
///|
fn T::m(self : T, x : Int) -> Unit {
println(self.0 + x)
}
///|
pub fn f(t : T, x : Int) -> Unit {
x |> t.m()
// ^^^^ Error: Unsupported expression after the pipe operator.
}
Suggestion#
To fix this error, you can change the invalid pipe expression to normal function or method application.
///|
pub struct T(Int)
///|
pub fn make(x : Int) -> T {
T(x)
}
///|
fn T::m(self : T, x : Int) -> Unit {
println(self.0 + x)
}
///|
pub fn f(t : T, x : Int) -> Unit {
(fn(x : Int) { println(x) })(x)
t.m(x)
}