T35
Error
Types
T35 — Values worked out from each other with neither declared
Two derived values — in one body, or in two stores — that each read the other, or one that reads itself: neither has a type to start from, so one of them must say what it is.
What the compiler said
error[T35]: `total` and `shipping` are each worked out from the other, so neither says what it is --> src/App.wf:3:5 | 3 | derived total = prices.sum() + shipping | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Declare what one of them is: `derived total: T = …` = docs: https://webfluent.monzeromer.dev/errors/T35
The fix
Broken
store Cart {
state prices: [Number] = [3, 4]
derived total = prices.sum() + shipping
derived shipping = if total > 50 { 0 } else { 5 }
}
page P(path: "/", title: "Cart", description: "D") {
use Cart
Heading("Cart").h1
Text("{Cart.total}")
}
Fixed
store Cart {
state prices: [Number] = [3, 4]
derived subtotal = prices.sum()
derived shipping = if subtotal > 50 { 0 } else { 5 }
derived total = subtotal + shipping
}
page P(path: "/", title: "Cart", description: "D") {
use Cart
Heading("Cart").h1
Text("{Cart.total}")
}
Untangle them, so one is worked out from the other and not back —
usually by naming what both read (subtotal above). Where the loop is
meant, declare what one of them is: derived total: Number = ….
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.
A derived value is worked out after what it reads, wherever that is
declared — below it, in another store, in a store further down — so the
order declarations are written in never changes a type. Two that read each
other, or one that reads itself, have nothing to start from: neither type
can be worked out first.
lints cannot lower it: it would ship a broken page.