Skip to content

Commit

Permalink
feat: add error codes index
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfettes committed Feb 5, 2025
1 parent 192a6dc commit 1e43c63
Show file tree
Hide file tree
Showing 166 changed files with 878 additions and 0 deletions.
9 changes: 9 additions & 0 deletions next/language/error_codes/E0001.md
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>
59 changes: 59 additions & 0 deletions next/language/error_codes/E2000.md
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.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3001

Lexing error
3 changes: 3 additions & 0 deletions next/language/error_codes/E3002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3002

Parse error
21 changes: 21 additions & 0 deletions next/language/error_codes/E3003.md
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!")
}
```
22 changes: 22 additions & 0 deletions next/language/error_codes/E3004.md
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!")
}
```
26 changes: 26 additions & 0 deletions next/language/error_codes/E3005.md
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.
```
25 changes: 25 additions & 0 deletions next/language/error_codes/E3006.md
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
}
```
15 changes: 15 additions & 0 deletions next/language/error_codes/E3007.md
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
```
17 changes: 17 additions & 0 deletions next/language/error_codes/E3008.md
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
```
46 changes: 46 additions & 0 deletions next/language/error_codes/E3009.md
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")
}
}
```
33 changes: 33 additions & 0 deletions next/language/error_codes/E3010.md
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 + "!")
}
```
3 changes: 3 additions & 0 deletions next/language/error_codes/E3011.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3011

Invalid left value for assignment.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3012.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3012

Record pattern and map pattern cannot be mixed.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3013.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3013

Map patterns are always open, the `..` is useless.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3014.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3014

Inline wasm syntax error.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3015.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3015

The parameter already has default value `None`.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3016.md
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~`?
3 changes: 3 additions & 0 deletions next/language/error_codes/E3017.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3017

JSON parse error.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3018.md
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.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3019.md
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.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3020.md
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 }`.
3 changes: 3 additions & 0 deletions next/language/error_codes/E3800.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E3800

Expecting a newline or `;` here, but encountered another delimiter.
41 changes: 41 additions & 0 deletions next/language/error_codes/E4000.md
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
}
```
3 changes: 3 additions & 0 deletions next/language/error_codes/E4001.md
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.
3 changes: 3 additions & 0 deletions next/language/error_codes/E4002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# E4002

The modifier is not supported here.
3 changes: 3 additions & 0 deletions next/language/error_codes/E4003.md
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.
3 changes: 3 additions & 0 deletions next/language/error_codes/E4004.md
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.
Loading

0 comments on commit 1e43c63

Please sign in to comment.