2024-11-04
Language Updatesβ
- Compile-time Constants Support
- Introduced support for constants declared with
const C = ..., where names start with uppercase letters. Must be built-in numeric types orString. Constants can be used as regular values and for pattern matching. Currently, the values of constants can only be literals.
- Introduced support for constants declared with
const MIN_INT = 0x1000_0000
const MAX_INT = 0x7fff_ffff
fn classify_int(x : Int) -> Unit {
match x {
MIN_INT => println("smallest int")
MAX_INT => println("largest int")
_ => println("other int")
}
}
fn main {
classify_int(MIN_INT) // smallest int
classify_int(MAX_INT) // largest int
classify_int(42) // other int
}
- Improved Unused Warnings
- Added detection for unused parameters in
enum:
enum E {
// Compiler warns if y is unused
C(~x : Int, ~y : Int)
}
fn f(x : E) -> Unit {
match x {
C(~x, ..) => println(x)
}
}
fn main {
f(C(x=1, y=2))
}
- Added detection for unused default parameter values (default off):
// The function `f` is private and that the caller always provides a value for `x` explicitly when calling it.
// If warning 32 is enabled (which is off by default), the compiler will notify the developer that the default value for `x` is unused.
fn f(~x : Int = 0) -> Unit {
println(x)
}
fn main {
f(x=1)
}
- Direct Function Imports
- Functions from other packages can now be directly imported without the
@pkg.prefix. To set this up, you must declare the functions in the"value"field of themoon.pkg.jsonconfiguration file.
- Functions from other packages can now be directly imported without the
{
"import": [
{
"path": "moonbitlang/pkg",
"alias": "pkg",
"value": ["foo", "bar"]
}
]
}
In this example, the functions foo and bar from the package moonbitlang/pkg can be called directly without the prefix @pkg..
-
Native JavaScript
BigIntSupportBigInttype compiles to native JavaScriptBigInt, with efficient pattern matching using switch statements.
-
Experimental: JavaScript backend generates
.d.tsfor exported functions- JavaScript backend now generates
.d.tsfiles based on exported functions specified inmoon.pkg.json, enhancing TypeScript/JavaScript integration. (*This feature for exporting complex types is still under design, and for now, it generates TypeScript'sanytype.)
- JavaScript backend now generates
IDE Updatesβ
-
Block-line Support
- Introduced special
block-linemarkers (///|) in top-level comments (///) to enhance code readability and structure:
- Use
moon fmt --block-stylecan automatically add these markers. In the future, incremental code parsing and type checking based on block-line markers will further enhance the responsiveness and usability of the Language Server Protocol (LSP), improving development efficiency.
- Introduced special
-
MoonBit Online IDE can visit GitHub repos for instant review, edit, and test.
- Go to a MoonBit-based repo on GitHub.
- Replace github.com with
try.moonbitlang.com.
-
Test Coverage Visualization
- Added support for visualizing test coverage in the test explorer:

- Added support for visualizing test coverage in the test explorer:
-
AI Features
- Added
/doc-pubcommand for generating documentation for public functions. - Fixed issue where
/doccommand would overwrite pragmas. - Patch now verifies generated test cases:

- Added
Build System Updatesβ
- Package Checking
moon checksupports checking specified packages and their dependencies:moon check /path/to/pkg.
MoonBit Markdown Libraryβ
- Open Source
- The MoonBit Markdown library is now open source, and available for download on MoonBit's package manager mooncakes.io.













