From bb1bd90d4fd87586bb44360148766a9bebc2dca8 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 16 Oct 2025 11:10:54 +0800 Subject: [PATCH 1/2] some weird interactions here --- quickcheck/arbitrary_test.mbt | 23 +++++++++++++++++++++++ quickcheck/utils.mbt | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/quickcheck/arbitrary_test.mbt b/quickcheck/arbitrary_test.mbt index 000c9e81d..fa5ac7032 100644 --- a/quickcheck/arbitrary_test.mbt +++ b/quickcheck/arbitrary_test.mbt @@ -103,3 +103,26 @@ test "arbitrary gen bytes" { ), ) } + + +///| +priv trait Test0 { + sum(Self, x? : Int, y? : Int, z? : Int) -> Int +} + +///| +impl Test0 for Int with sum(self, x~ : Int = 3, y? = 2, z?) { + // weird both x~ and y? work here?? + // y? should warn + self + x + y + (if z is Some(x) { x } else { 0 }) +} + +///| +test "default argument in trait method" { + inspect((10).sum(), content="15") + // weird warnings appear here + // Calling local `impl` with `.` or `Type::meth(..)` is deprecated, use `Trait::meth(..)` instead. + // this seems to be inconsistent with the fact that `Type::meth` will call `Trait::meth` + inspect((10).sum(x=1), content="13") + inspect((10).sum(x=1, y=1), content="12") +} diff --git a/quickcheck/utils.mbt b/quickcheck/utils.mbt index 4123e0ec3..855195d93 100644 --- a/quickcheck/utils.mbt +++ b/quickcheck/utils.mbt @@ -21,3 +21,21 @@ pub fn[X : Arbitrary] samples(x : Int) -> Array[X] { } array } + + +///| +priv trait Test0 { + sum(Self, x? : Int, y? : Int) -> Int +} + +///| +impl Test0 for Int with sum(self, x? : Int = 3, y? = 2) { + self + x + y +} + +///| +test "default argument in trait method" { + inspect((10).sum(), content="15") + inspect((10).sum(x=1), content="13") + inspect((10).sum(x=1, y=1), content="12") +} From c57ad3232b17fd7de24deb9821100f23ac11b400 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 16 Oct 2025 11:15:19 +0800 Subject: [PATCH 2/2] tweak --- quickcheck/arbitrary_test.mbt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/quickcheck/arbitrary_test.mbt b/quickcheck/arbitrary_test.mbt index fa5ac7032..5d1ed5c88 100644 --- a/quickcheck/arbitrary_test.mbt +++ b/quickcheck/arbitrary_test.mbt @@ -106,12 +106,12 @@ test "arbitrary gen bytes" { ///| -priv trait Test0 { +trait Test0 { sum(Self, x? : Int, y? : Int, z? : Int) -> Int } ///| -impl Test0 for Int with sum(self, x~ : Int = 3, y? = 2, z?) { +pub impl Test0 for Int with sum(self, x~ : Int = 3, y? = 2, z?) { // weird both x~ and y? work here?? // y? should warn self + x + y + (if z is Some(x) { x } else { 0 }) @@ -124,5 +124,6 @@ test "default argument in trait method" { // Calling local `impl` with `.` or `Type::meth(..)` is deprecated, use `Trait::meth(..)` instead. // this seems to be inconsistent with the fact that `Type::meth` will call `Trait::meth` inspect((10).sum(x=1), content="13") + inspect(Int::sum((10), x=1, y=1), content="12") inspect((10).sum(x=1, y=1), content="12") }