diff --git a/quickcheck/arbitrary_test.mbt b/quickcheck/arbitrary_test.mbt index 000c9e81d..5d1ed5c88 100644 --- a/quickcheck/arbitrary_test.mbt +++ b/quickcheck/arbitrary_test.mbt @@ -103,3 +103,27 @@ test "arbitrary gen bytes" { ), ) } + + +///| +trait Test0 { + sum(Self, x? : Int, y? : Int, z? : Int) -> Int +} + +///| +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 }) +} + +///| +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(Int::sum((10), x=1, y=1), content="12") + 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") +}