Why this fires¶
An expression was called like a function (expr(...)), but its type isn't a function type — it's some other, non-callable type.
let n = 42
let r = n(1, 2)
// ^^^^^^^ error[TE101]: cannot call non-function type intFix it¶
1. Don't call it¶
If the value was never meant to be called, remove the call parentheses:
let n = 42
print(n)2. Call the right thing¶
A common cause is a typo or shadowing — a local variable with the same name as a function hides it:
fn compute(x: int) -> int { return x * 2 }
fn use_it() {
let compute = 42 // shadows the function `compute`
print(compute(1)) // TE101 — `compute` is now an int here
}Rename the local variable, or call the function before shadowing it.
3. An optional function needs an optional call¶
For a parameter declared with ?:, the function value itself may be nil:
fn Card(children?: fn() -> View) -> View {
<section>{children()}</section>
// ^^ TE101: `children` may be nil
}Its type is written (fn() -> View)?. The parentheses matter:
(fn() -> View)?— the function value is optional.fn() -> View?— the function is required and its return value is optional.
Use the optional-call operator when the absence of the callback should simply
produce nil:
fn Card(children?: fn() -> View) -> View {
<section>{children?.()}</section>
}The editor offers Call only when present as a preferred quick fix and
changes only the call's opening ( to ?.(. If absence is an error instead,
check the value against nil and handle that branch before calling it.