T26
Error
Types
T26 — An action that returns a value and does not say what
What an action returns is part of what it is: a caller in another file reads it without reading the action's body. An action that returns a value declares it, -> T, and every return is held to it.
What the compiler said
error[T26]: `total` returns a value and does not say what --> src/App.wf:3:5 | 3 | action total() { | ^^^^^^^^^^^^^^^^ = help: Say so: `action total(…) -> Number` = docs: https://webfluent.monzeromer.dev/errors/T26
Your editor offers this fix: Declare -> Number. wf fix --code T26 applies it to every place it fits.
The fix
Broken
store Cart {
state items: [Number] = [3, 4]
action total() {
return items.sum()
}
}
page P(path: "/", title: "T", description: "D") {
use Cart
Heading("Cart").h1
Text("{Cart.total()}")
}
Fixed
store Cart {
state items: [Number] = [3, 4]
action total() -> Number {
return items.sum()
}
}
page P(path: "/", title: "T", description: "D") {
use Cart
Heading("Cart").h1
Text("{Cart.total()}")
}
Say what it returns after its parameters: action total() ->
Number { … }. The editor's quick fix and wf fix --code T26 write the
type the checker works out from the body, when it can be written.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Error.
What an action returns is part of what it is. A page in another file
calls Cart.total() and reads what comes back; with the type declared
beside the action's name it knows what that is without reading the body,
and every return in the body is held to it. An action that returns
nothing declares nothing.
lints cannot lower it: it would ship a broken page.