8000 fix: update some deprecated usages by Topology2333 · Pull Request #2271 · moonbitlang/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: update some deprecated usages #2271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions array/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn[T] Array::makei(
/// test "Array::shuffle_in_place" {
/// let arr = [1, 2, 3, 4, 5]
/// fn rand(upper : Int) -> Int {
/// let rng = @random.new()
/// let rng = @random.Rand::new()
/// rng.int(limit=upper)
/// }
/// Array::shuffle_in_place(arr, rand=rand)
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn[T] shuffle_in_place(self : Array[T], rand~ : (Int) -> Int) -> Unit {
/// test {
/// let arr = [1, 2, 3, 4, 5]
/// fn rand(upper : Int) -> Int {
/// let rng = @random.new()
/// let rng = @random.Rand::new()
/// rng.int(limit=upper)
/// }
/// let _shuffled = Array::shuffle(arr, rand=rand)
Expand Down
2 changes: 1 addition & 1 deletion array/view.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub fn[A, B] View::foldi(
/// # Example
/// ```mbt
/// test {
/// let sum = [1, 2, 3, 4, 5][:].rev_foldi(init=0, fn { index, sum, _elem => sum + index })
/// let sum = [1, 2, 3, 4, 5][:].rev_foldi(init=0, fn(index, sum, _elem) { sum + index })
/// assert_eq(sum, 10)
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion builtin/bytes.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn Bytes::makei(length : Int, value : (Int) -> Byte) -> Bytes {
///
/// ```moonbit
/// test "Bytes::of_string" {
/// let bytes = Bytes::of_string("ABC")
/// let bytes = "ABC".to_bytes()
/// inspect(bytes, content="b\"\\x41\\x00\\x42\\x00\\x43\\x00\"")
/// }
/// ```
Expand Down
10 changes: 5 additions & 5 deletions builtin/intrinsics.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ pub impl Compare for Char with compare(self, other) = "%char_compare"
///
/// ```moonbit
/// test "Char::default" {
/// assert_true(Char::default().to_string() == "\x00")
/// assert_true(Char::default().to_string() == "\u0000")
/// }
/// ```
pub impl Default for Char with default() = "%char_default"
Expand Down Expand Up @@ -1726,14 +1726,14 @@ pub fn String::op_get(self : String, idx : Int) -> Char = "%string_get"
/// ```moonbit
/// test "String::get" {
/// let s = "Hello, 世界"
/// inspect(s.get(0), content="H")
/// inspect(s.get(7), content="世")
/// inspect(s.charcode_at(0), content="72")
/// inspect(s.char_at(7), content="世")
/// }
///
/// test "panic String::get/out_of_bounds" {
/// let s = "Hello"
/// ignore(s.get(-1)) // Negative index
/// ignore(s.get(5)) // Index equals length
/// ignore(s.charcode_at(-1)) // Negative index
/// ignore(s.charcode_at(5)) // Index equals length
/// }
/// ```
#deprecated("use `charcode_at` instead")
Expand Down
4 changes: 2 additions & 2 deletions builtin/string.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ pub fn String::charcode_at(self : String, index : Int) -> Int = "%string_get"
/// ```mbt
/// test "String::codepoint_at" {
/// let s = "Hello🤣";
/// inspect(s.codepoint_at(0), content="H");
/// inspect(s.codepoint_at(5), content="🤣"); // Returns full emoji character
/// inspect(s.iter().nth(0).unwrap(), content="H");
/// inspect(s.iter().nth(5).unwrap(), content="🤣"); // Returns full emoji character
/// }
/// ```
///
Expand Down
4 changes: 2 additions & 2 deletions hashmap/hashmap.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ fn[K : Hash + Eq, V] get_with_hash(self : T[K, V], key : K, hash : Int) -> V? {
/// ```moonbit
/// test "op_get" {
/// let map = @hashmap.of([("key", 42)])
/// inspect(map["key"], content="Some(42)")
/// inspect(map["nonexistent"], content="None")
/// inspect(map.get("key"), content="Some(42)")
/// inspect(map.get("nonexistent"), content="None")
/// }
/// ```
#deprecated("Use `get` instead. `op_get` will return `V` instead of `Option[V]` in the future.")
Expand Down
10 changes: 5 additions & 5 deletions immut/list/list.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ pub fn[A, B] fold_righti(self : T[A], f : (Int, A, B) -> B, init~ : B) -> B {
///
/// ```mbt
/// test {
/// let r = @list.zip(@list.of([1, 2, 3, 4, 5]), @list.of([6, 7, 8, 9, 10]))
/// let r = @list.of([1, 2, 3, 4, 5]).zip(@list.of([6, 7, 8, 9, 10]))
/// assert_eq(r, Some(@list.from_array([(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)])))
/// }
/// ```
Expand Down Expand Up @@ -626,7 +626,7 @@ pub fn[A] repeat(n : Int, x : A) -> T[A] {
///
/// ```mbt
/// test {
/// let ls = @list.intersperse(@list.from_array(["1", "2", "3", "4", "5"]), "|")
/// let ls = (@list.from_array(["1", "2", "3", "4", "5"])).intersperse("|")
/// assert_eq(ls, @list.from_array(["1", "|", "2", "|", "3", "|", "4", "|", "5"]))
/// }
/// ```
Expand All @@ -651,7 +651,7 @@ pub fn[A] is_empty(self : T[A]) -> Bool {
///
/// ```mbt
/// test {
/// let (a,b) = @list.unzip(@list.from_array([(1,2),(3,4),(5,6)]))
/// let (a,b) = @list.from_array([(1,2),(3,4),(5,6)]).unzip()
/// assert_eq(a, @list.from_array([1, 3, 5]))
/// assert_eq(b, @list.from_array([2, 4, 6]))
/// }
Expand All @@ -677,7 +677,7 @@ pub fn[A, B] unzip(self : T[(A, B)]) -> (T[A], T[B]) {
///
/// ```mbt
/// test {
/// let ls = @list.flatten(@list.from_array([@list.from_array([1,2,3]), @list.from_array([4,5,6]), @list.from_array([7,8,9])]))
/// let ls = (@list.from_array([@list.from_array([1,2,3]), @list.from_array([4,5,6]), @list.from_array([7,8,9])])).flatten()
/// assert_eq(ls, @list.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9]))
/// }
/// ```
Expand Down Expand Up @@ -758,7 +758,7 @@ pub fn[A : Compare] minimum(self : T[A]) -> A? {
///
/// ```mbt
/// test {
/// let ls = @list.sort(@list.from_array([1,123,52,3,6,0,-6,-76]))
/// let ls = (@list.from_array([1,123,52,3,6,0,-6,-76])).sort()
/// assert_eq(ls, @list.from_array([-76, -6, 0, 1, 3, 6, 52, 123]))
/// }
/// ```
Expand Down
8 changes: 4 additions & 4 deletions immut/sorted_map/types.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
/// test {
/// let map1 = @sorted_map.of([(3, "three"), (8, "eight"), (1, "one")])
/// let map2 = map1.add(2, "two").remove(3)
/// assert_eq(map2.lookup(2), Some("two"))
/// assert_eq(map2.get(2), Some("two"))
/// let map3 = map2.add(2, "updated")
/// assert_eq(map2.lookup(3), None)
/// assert_eq(map3.lookup(3), None)
/// assert_eq(map3.lookup(2), Some("updated"))
/// assert_eq(map2.get(3), None)
/// assert_eq(map3.get(3), None)
/// assert_eq(map3.get(2), Some("updated"))
/// }
/// ```
enum T[K, V] {
Expand Down
6 changes: 3 additions & 3 deletions math/prime.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ let small_primes : Array[@bigint.BigInt] = [
/// ```moonbit
/// ///|
/// test "is_probable_prime" {
/// let rand = @random.new()
/// let rand = @random.Rand::new()
/// let prime = BigInt::from_string("17")
/// let composite = BigInt::from_string("15")
/// inspect(is_probable_prime(prime, rand), content="true")
Expand All @@ -208,7 +208,7 @@ let small_primes : Array[@bigint.BigInt] = [
///
/// ///|
/// test "panic is_probable_prime/invalid_iterations" {
/// let rand = @random.new()
/// let rand = @random.Rand::new()
/// ignore(is_probable_prime(42N, rand, iters=0)) // Panics with "non-positive iters for probably prime"
/// }
/// ```
10000 Expand Down Expand Up @@ -251,7 +251,7 @@ pub fn is_probable_prime(
///
/// ```moonbit
/// test "probable_prime" {
/// let rand = @random.new()
/// let rand = @random.Rand::new()
/// let prime = probable_prime(64, rand)
/// inspect(is_probable_prime(prime, rand), content="true")
/// }
Expand Down
4 changes: 2 additions & 2 deletions option/option.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ test "bind" {
/// ```mbt
/// test "flatten_example" {
/// let a = Some(Some(42));
/// assert_eq(@option.flatten(a), Some(42))
/// assert_eq(a.flatten(), Some(42))
/// let b : Int?? = Some(None)
/// assert_eq(@option.flatten(b), None)
/// assert_eq(b.flatten(), None)
/// }
/// ```
pub fn[T] flatten(self : T??) -> T? {
Expand Down
2 changes: 1 addition & 1 deletion priority_queue/priority_queue.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn[A] copy_node(x : Node[A]) -> Node[A] {
/// ```mbt
/// test "copy_example" {
/// let queue = @priority_queue.of([1, 2, 3, 4])
/// let queue2 = @priority_queue.copy(queue)
/// let queue2 = queue.copy()
/// assert_eq(queue2.length(), 4)
/// }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions random/random.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub fn float(self : Rand) -> Float {
///
/// ```moonbit
/// test "Rand::bigint" {
/// let rand = @random.new()
/// let rand = Rand::new()
/// let n = rand.bigint(8) // Generate random 8-bit number
/// inspect(n.bit_length() <= 8, content="true")
/// }
Expand Down Expand Up @@ -304,7 +304,7 @@ test "umul128: handles zero correctly" {
/// # Example
/// ```mbt
/// test "shuffle example" {
/// let r = @random.new()
/// let r = Rand::new()
/// let a = [1, 2, 3, 4, 5]
/// r.shuffle(
/// a.length(),
Expand Down
2 changes: 1 addition & 1 deletion sorted_set/README.mbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ SortedSet implements to_string (i.e. Show trait), which allows you to directly o
```moonbit
test {
let set = @sorted_set.from_array([1, 2, 3])
assert_eq(set.to_string(), "@sorted_set.of([1, 2, 3])")
assert_eq(set.to_string(), "@sorted_set.from_array([1, 2, 3])")
}
```

Loading
Loading
0