Skip to content

Commit

Permalink
fix #1144
Browse files Browse the repository at this point in the history
  • Loading branch information
bob.hongbo.zhang authored and bobzhang committed Oct 19, 2024
1 parent 622edb9 commit 0930bce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -982,3 +982,7 @@ pub fn iter2[A](self : Array[A]) -> Iter2[Int, A] {
},
)
}

pub fn Array::default[T]() -> Array[T] {
[]
}
8 changes: 8 additions & 0 deletions builtin/array_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,11 @@ test "array_dedup - edge cases" {
array.dedup()
inspect!(array, content="[1, 2, 3, 4, 5]")
}

struct MX {
mm_num : Array[Int]
} derive(Default, ToJson)

test {
@json.inspect!(MX::default(), content={ "mm_num": [] })
}
1 change: 1 addition & 0 deletions builtin/builtin.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl Array {
compare[T : Compare + Eq](Self[T], Self[T]) -> Int
contains[T : Eq](Self[T], T) -> Bool
dedup[T : Eq](Self[T]) -> Unit
default[T]() -> Self[T]
drain[T](Self[T], Int, Int) -> Self[T]
each[T](Self[T], (T) -> Unit) -> Unit
eachi[T](Self[T], (Int, T) -> Unit) -> Unit
Expand Down

0 comments on commit 0930bce

Please sign in to comment.