Skip to content
Open
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
24 changes: 24 additions & 0 deletions quickcheck/arbitrary_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upstream T::new_f (x.new_f) conflict with (x.new_f)

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")
}
18 changes: 18 additions & 0 deletions quickcheck/utils.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading