Lyricdev
GitHub

LYR-SEM0013

a call on something that is not a function

error · spec 08-expressions

A call f(…) whose callee is not a function value: a number, a field that is no function, or a type T(…) that declares no static fn new.

Explanation

Only functions, methods and function values are called. T(…) on a type is short for T.new(…) and needs that factory; a struct or class is otherwise built with its initializer T { … }.

Call a function, build the value with T { … }, or declare static fn new.

Wrong

struct Point { x: int }

fn main(): void {
    let p = Point(1);
    let _ = p;
}
struct Point { x: int }

fn main(): void {
    let p = Point { x = 1 };
    let _ = p;
}