E4069#
Unexpected main function in the non-main package.
In MoonBit, packages are divided into two types: main packages and non-main
packages. Non-main packages are often used as libraries to provide functionality
to other packages. Main packages, on the other hand, are the entry points of the
program. Therefore, non-main packages should not contain a main function.
Sometimes, people use the main function for testing. In such cases, we recommend
using the test block to write tests, instead of using the main function. See
the test section of the MoonBit documentation for
more information.
Erroneous example#
Suppose in package lib:
lib/moon.pkg:
lib/lib.mbt:
///|
fn main {
println("Hello, world!")
}
Suggestion#
You can remove the main function from the non-main package:
///|
pub fn message() -> String {
"Hello, world!"
}
Alternatively, you can set the package to be a main package by setting
"is-main" to true in the package configuration file.
lib/moon.pkg:
options(
"is-main": true,
)
You can also move the main function to a different package, say main:
main/moon.pkg:
import {
"moonbit-community/E4069-fixed" @lib,
}
options(
"is-main": true,
)
main/main.mbt:
///|
fn main {
println(@lib.message())
}