A main that does not return an int exits with 0
The first program no longer ends in a 0, and the appendix says what the compiler knows about main. The unit type is spelled void in the signatures that wrote unit, which is its value, and print-n-times has a loop clause for its body. 🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-5-5) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
parent
4f8da92dc2
commit
84000bf384
2 changed files with 11 additions and 12 deletions
|
|
@ -67,12 +67,12 @@ When compiled, the frontend rejects this with:
|
|||
Type Error: Function 'greet' requires a type signature (: greet ...) at hello.bjo:1:1
|
||||
}|
|
||||
|
||||
@strong{Why it happens:} Unlike local helper functions defined inside another function, every top-level definition in a module must carry an explicit type signature. The compiler requires this so that module interfaces are self-documenting and can be emitted into the compiled assembly's public metadata without requiring whole-program inference across files. The only exception is @code{main}, which has a fixed signature known to the compiler.
|
||||
@strong{Why it happens:} Unlike local helper functions defined inside another function, every top-level definition in a module must carry an explicit type signature. The compiler requires this so that module interfaces are self-documenting and can be emitted into the compiled assembly's public metadata without requiring whole-program inference across files. The only exception is @code{main}: the compiler knows what it takes, the arguments as a @code{(Vec string)}, and what it returns is the exit code when it is an int.
|
||||
|
||||
@strong{How to fix it:} Add an explicit signature right before the definition:
|
||||
|
||||
@codeblock[#:lang "bjolang"]|{
|
||||
(: greet (-> string unit))
|
||||
(: greet (-> string void))
|
||||
(defun (greet name)
|
||||
(println (str "Hello, " name)))
|
||||
}|
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue