-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
192a6dc
commit 1e43c63
Showing
166 changed files
with
878 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# E0001 | ||
|
||
There is an internal error occurred to the compiler. Usually this means you have | ||
discovered a bug in the compiler. | ||
|
||
A bug report containing the error description and relevant code would be | ||
greatly appreciated. You can submit the bug report here: | ||
|
||
<https://github.com/moonbitlang/moonbit-docs/issues/new?labels=bug,ICE> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# E2000 | ||
|
||
The usage of function (type, trait, etc.) is flagged with alert. Usually, alert | ||
message comes with a alert kind and a detailed description of the alert. If you | ||
are using the function from a library, these alerts are set by the library | ||
author to provide some more information on the usage of the function | ||
|
||
There are some common alerts that you may encounter: | ||
|
||
* `deprecated`: indicates the function (type, trait, etc) is deprecated and | ||
should not be used or migrate to new APIs. | ||
* `unsafe`: indicates this API panics, breaks internal invariants, has undefined | ||
behavior under some circumstances. The concrete semantics of this kind of | ||
alerts may be different across packages, and please consult the documentation | ||
or the author of these packages for further details. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
/// @alert deprecated "Use `greet` instead" | ||
fn greeting() -> String { | ||
"Hello!" | ||
} | ||
fn greet(name~ : String = "") -> String { | ||
if name != "" { | ||
"Hello!" | ||
} else { | ||
"Hello, \{name}!" | ||
} | ||
} | ||
fn main() -> Unit { | ||
println(greeting()) | ||
// ^~~~~~~~ Warning (Alert deprecated): Use `greet` instead(2000) | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
One way to fix the alert, is to change your code as suggested by the message (like `deprecated`): | ||
|
||
```moonbit | ||
// ... code in the example above ... | ||
fn main() -> Unit { | ||
println(greet(name="world")) | ||
} | ||
``` | ||
|
||
If you clearly know what you are doing and would like to suppress the alert, you can change the `moon.pkg.json` file for packages where you would like to disable **this kind of alert**. For example: | ||
|
||
```moonbit | ||
{ | ||
// ... other fields in the file | ||
"alert-list": "-deprecated" | ||
} | ||
``` | ||
|
||
NOTE: There is no way to disable alerts for a line/file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3001 | ||
|
||
Lexing error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3002 | ||
|
||
Parse error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# E3003 | ||
|
||
`init` and `main` function must have no arguments and no return value. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
fn main() -> Unit { | ||
println("Hello, world!") | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
Remove the argument list and return type annotation, as: | ||
|
||
```moonbit | ||
fn main { | ||
println("Hello, world!") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# E3004 | ||
|
||
Missing parameters list. Add `()` after the name of the function if it takes 0 | ||
parameter. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
fn greet { | ||
println("Hello, world!") | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
Add `()` after the function name. | ||
|
||
```moonbit | ||
fn greet() { | ||
println("Hello, world!") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# E3005 | ||
|
||
There is no such visibility for the entity (function/type/trait/...). | ||
|
||
Usually, this means that you put an `priv` visibility modifier on a entity is | ||
by-default private. | ||
|
||
See the [Access | ||
Control](https://docs.moonbitlang.com/en/latest/language/packages.html#access-control) | ||
section of [MoonBit Language | ||
Documentation](https://docs.moonbitlang.com/en/latest/language/index.html) for a | ||
detailed explanaion on the visibility in MoonBit. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
priv let value = 3 | ||
``` | ||
|
||
## Suggestion | ||
|
||
Remove the visibility modifier from the definition of the entity: | ||
|
||
```moonbit | ||
let value = 3 // This is already `priv` by default. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# E3006 | ||
|
||
There is no individual visibility control fro enum constructors. | ||
|
||
Usually, this means that you put an `priv` or `pub` visibility modifier on a enum constructor. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
enum A { | ||
priv A1 | ||
pub A2 | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
Remove the visibility modifier from the definition of the enum constructor: | ||
|
||
```moonbit | ||
enum A { | ||
A1 | ||
A2 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# E3007 | ||
|
||
Wrong location of `..` in pattern match. Put `..` at the end of the pattern. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
let {a, .., c} = s | ||
``` | ||
|
||
## Suggestion | ||
|
||
```moonbit | ||
let {a, c, ..} = s | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# E3008 | ||
|
||
There are multiple `..` patterns in array pattern. Remove until there is only one `..` pattern in array pattern. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
let [fst, .., .., snd] = array | ||
``` | ||
|
||
## Suggestion | ||
|
||
Remove the extra `..` pattern. | ||
|
||
```moonbit | ||
let [fst, .., snd] = array | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# E3009 | ||
|
||
Record pattern cannot contain only `..`, use wildcard pattern `_` instead. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
struct Point { | ||
x: Int, | ||
y: Int | ||
} | ||
fn process_point(p: Point) { | ||
match p { | ||
{ .. } -> println("Got a point") | ||
} | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
Use the wildcard pattern `_` instead of `{ .. }`: | ||
|
||
```moonbit | ||
struct Point { | ||
x: Int, | ||
y: Int | ||
} | ||
fn process_point(p: Point) { | ||
match p { | ||
_ -> println("Got a point") | ||
} | ||
} | ||
``` | ||
|
||
You can also use `{ .. }` along with other fields if you want to match specific fields: | ||
|
||
```moonbit | ||
fn process_point(p: Point) { | ||
match p { | ||
{ x: 0, .. } -> println("Point on y-axis") | ||
_ -> println("Other point") | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# E3010 | ||
|
||
Only labelled arguments can have default value. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
fn greet(name = "World") { | ||
println("Hello, " + name + "!") | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
Use a labelled argument with `~` if you want to provide a default value: | ||
|
||
```moonbit | ||
fn greet(~name = "World") { | ||
println("Hello, " + name + "!") | ||
} | ||
// Can be called as: | ||
greet() // Uses default value "World" | ||
greet(~name = "Alice") // Uses provided value "Alice" | ||
``` | ||
|
||
Or remove the default value if you want to keep it as a positional argument: | ||
|
||
```moonbit | ||
fn greet(name: String) { | ||
println("Hello, " + name + "!") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3011 | ||
|
||
Invalid left value for assignment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3012 | ||
|
||
Record pattern and map pattern cannot be mixed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3013 | ||
|
||
Map patterns are always open, the `..` is useless. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3014 | ||
|
||
Inline wasm syntax error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3015 | ||
|
||
The parameter already has default value `None`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3016 | ||
|
||
Unexpected `~` in argument. Did you mean `label=pattern` or `label~`? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3017 | ||
|
||
JSON parse error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3018 | ||
|
||
Bounds of range pattern must be constant, named constant or wildcard. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3019 | ||
|
||
Inclusive range pattern `a..=b` cannot have `_` as upper bound. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3020 | ||
|
||
Unexpected `=` in struct expression. The correct syntax for struct expression is `{ field: expression }`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E3800 | ||
|
||
Expecting a newline or `;` here, but encountered another delimiter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# E4000 | ||
|
||
Generic type variable name is already used. | ||
|
||
## Erroneous example | ||
|
||
```moonbit | ||
struct Container[T, T] { | ||
value : T | ||
} | ||
fn transform[A, A](x : A) -> A { | ||
x | ||
} | ||
``` | ||
|
||
## Suggestion | ||
|
||
Use different names for type variables: | ||
|
||
```moonbit | ||
struct Container[T1, T2] { | ||
value : T1 | ||
} | ||
fn transform[A, B](x : A) -> B { | ||
// ... implementation | ||
} | ||
``` | ||
|
||
Or remove the duplicate type parameter if you meant to use the same type: | ||
|
||
```moonbit | ||
struct Container[T] { | ||
value : T | ||
} | ||
fn transform[A](x : A) -> A { | ||
x | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E4001 | ||
|
||
A field with different visibility cannot be declared within a struct. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E4002 | ||
|
||
The modifier is not supported here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E4003 | ||
|
||
This is a reserved type name. Cannot declare it as a type variable, type, or trait. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# E4004 | ||
|
||
Trait methods cannot have type parameters (be polymorphic). MoonBit currently does not support generic/polymorphic methods within trait definitions. |
Oops, something went wrong.