Skip to content

Commit c1eaa45

Browse files
doc: update E4162
1 parent dcdd3cc commit c1eaa45

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

next/language/error_codes/E4162.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# E4162
2+
3+
Local parameter is not function.
4+
5+
`#locals` is an attribute that aims to inline the given function parameter. This
6+
error is raised when the given parameter is not a function.
7+
8+
## Erroneous example
9+
10+
```{literalinclude} /sources/error_codes/4162_error/top.mbt
11+
:language: moonbit
12+
```
13+
14+
## Suggestion
15+
16+
Apply `locals` to local functions only.
17+
18+
```{literalinclude} /sources/error_codes/4162_fixed/top.mbt
19+
:language: moonbit
20+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "moonbit-community/E4162"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
///|
2+
#locals(init_)
3+
pub fn[A, B] fold(a : Array[A], init_~ : B, f : (B, A) -> B) -> B {
4+
// ^
5+
// This parameter is expected to be a function, but it is not.
6+
let mut acc = init_
7+
for x in a {
8+
acc = f(acc, x)
9+
}
10+
acc
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "moonbit-community/E4162-fixed"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
///|
2+
#locals(f)
3+
pub fn[A, B] fold(a : Array[A], init_~ : B, f : (B, A) -> B) -> B {
4+
let mut acc = init_
5+
for x in a {
6+
acc = f(acc, x)
7+
}
8+
acc
9+
}

0 commit comments

Comments
 (0)