20251014 MoonBit Monthly Update Vol.04
Version v0.6.29
Language Updates
-
Asynchronous Programming Enhancements
Added support for
async testandasync fn mainsyntax, enabling asynchronous tests and asynchronous main functions. Bothasync fn mainandasync testare based on themoonbitlang/asynclibrary and are currently supported on the native backend for Linux and macOS. For more details about async programming in MoonBit, see the documentation and GitHub repository ofmoonbitlang/async.Async testsdeclared with async test will run in parallel.///| async test "http request" { let (response, result) = @http.get("https://www.example.org") inspect(response.code, content="200") assert_true(result.text().has_prefix("<!doctype html>")) } -
Experimental Feature:
lexmatchExpressionAdded the
lexmatchexpression (experimental feature), which enables pattern matching onStringVieworBytesViewusing regular expressions.The following example matches two to four consecutive
'a'characters followed by a'b', capturing the consecutive'a's as variablea. For more detailed usage, refer to lexer.mbt in moonbitlang/parser and the lexmatch proposal in moonbit-evolution.lexmatch x with longest { (("a{2,4}" as a) "b", _) => Some(a.length()) _ => None } -
Unified Import Syntax with
usingIntroduced the
usingsyntax, which unifiesfnalias,traitalias, and simple typealias. When importing atypeortrait, the corresponding keyword must now be prefixed before the name.using @pkg { value, CONST, type Type, trait Trait, }In addition,
pub usingcan be used to achieve re-export, allowing definitions from other packages to be re-exported in the current package. In the future, thefnalias,traitalias, and simpletypealiassyntaxes will be deprecated — the functionality of creating aliases for external definitions will be replaced byusing, while creating aliases for definitions within the current package will be handled by the#aliasattribute. -
Methods in a trait now support optional parameters.
pub(open) trait Reader { async read(Self, buf : FixedArray[Byte], offset? : Int, len? : Int) -> Unit }The default value of an optional parameter is determined individually by each
impl. Different implementations can define their own default values or choose not to provide one at all — in that case, the optional parameter’s type within theimplwill beT?, whereNoneindicates that the user did not supply the argument. -
Operator Overloading via
#aliasAdded support for using
#aliasto overload operators such asop_get, providing better readability compared to theop_xxxnaming convention.// Previously `op_get` #alias("_[_]") fn[X] Array::get(self : Array[X], index : Int) -> X { ... } // Previously `op_set` #alias("_[_]=_") fn[X] Array::set(self : Array[X], index : Int, elem : X) -> Unit { ... } // Previously `op_as_view` #alias("_[_:_]") fn[X] Array::view( self : Array[X], start? : Int = 0, end? : Int = self.length(), ) -> ArrayView[X] { ... }Currently, the following operators are supported. The actual implementation names (e.g.,
get,set,view) can be freely chosen — simply attach the corresponding#aliasto enable operator overloading. It is recommended to use#aliasinstead ofop_xxxfor method-based operator overloading. (Note: Operators like+are overloaded through traits and are not affected by this change.) -
Removal of Long-Deprecated Syntax and Behaviors
Several language features that had been deprecated for a long time have now been officially removed:
Previously, methods defined in the form
fn meth(self : T, ..)were both methods and regular functions, allowing them to be called directly as standalone functions. This behavior had long been deprecated (with compiler warnings) and is now removed. The declarationfn meth(self : T, ..)is now equivalent tofn T::meth(self : T, ..). In the future, theself-form method definition itself may also be deprecated.The
direct_usefield in moon.pkg.json has been officially removed and replaced byusing.
Toolchain Updates
-
Wasm Toolchain Released — The Wasm version of the MoonBit toolchain is now available for x86 Darwin and ARM Linux users. 🔗 Read more
-
Experimental Build System (RR) — A new experimental version of the build system, codenamed
RR, has been introduced. It offers higher performance and better maintainability, and will eventually replace the current internal implementation ofmoon. You can enable it using the environment variableNEW_MOON=1or the command-line flag-Z rupes_recta. If you encounter any issues, please report them on GitHub Issues. -
moon fmtEnhancements — Now supports formatting of.mbt.mdfiles. -
moon info --no-aliasOption — Added a new option to hide type aliases when generating thepkg.generated.mbtifile.
Standard Library Updates
-
Improved Hash Security — To mitigate potential HashDoS attacks, hash computation is now randomized per process. This change has already been implemented in the JS backend.
-
Immutable
ArrayView—ArrayViewhas been changed to an immutable data structure, providing a unified slicing interface forArray,FixedArray, andImmutArray.


