E4191

E4191#

Compiler diagnostic name: mbt_check_non_test_toplevel.

Non-test toplevel in an mbt check documentation block.

Code fences marked as mbt check in doc comments are treated as document-test blocks. These blocks should contain test toplevels, such as test { ... }. Ordinary toplevel declarations are skipped and reported with this diagnostic.

Erroneous example#

The following mbt check block declares a normal helper function:

/// Returns the answer.
///
/// ```mbt check
/// fn helper() -> Int {
///   42
/// }
/// ```
pub fn answer() -> Int {
  42
}

MoonBit will report an error.

Suggestion#

Move the checked code into a test { ... } block:

/// Returns the answer.
///
/// ```mbt check
/// test {
///   inspect(answer(), content="42")
/// }
/// ```
pub fn answer() -> Int {
  42
}