T27
Error
Types
T27 — Two values with no type in common
The branches of an if or a match, the items of a list, or the two sides of ?? are one value, so they are one type: if ok { 1 } else { "none" } is a number one way and text the other, and nothing that reads it can say which. null on one side is fine — the value is then T?.
What the compiler said
error[T27]: `if left … 0 { … }` is `Number` one way and `String` the other, which have no type in common --> src/App.wf:3:5 | 3 | derived label = if left > 0 { left } else { "sold out" } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Make both the same type: show a number as text with a splice (`"{n}"`), or use `null` for nothing = docs: https://webfluent.monzeromer.dev/errors/T27
The fix
Broken
page P(path: "/", title: "Stock", description: "D") {
state left = 0
derived label = if left > 0 { left } else { "sold out" }
Heading("Stock").h1
Text("{label}")
}
Fixed
page P(path: "/", title: "Stock", description: "D") {
state left = 0
derived label = if left > 0 { "{left} left" } else { "sold out" }
Heading("Stock").h1
Text(label)
}
Make both sides the same type. Show a number as text with a
splice — "{left} left" — or give the value a case of its own: an enum
with payloads says "a count, or sold out" with names.
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.
The branches of an if or a match, the items of a list and the two
sides of ?? make one value, so they are one type. A value that is a
number one way and text the other has no type anything can be checked
against: label * 2 would be NaN on one branch and a number on the other,
and nothing could say which.
null on one side is not a disagreement: if ok { 1 } else { null } is a
Number?. An address, a colour or an id is a string, so it joins with
text.
lints cannot lower it: it would ship a broken page.