paulbutcher / ScalaMock

Native Scala mocking framework
http://scalamock.org/
MIT License
504 stars 100 forks source link

fix: cast args when applying mockFunctionValDef in scala 3 #529

Closed hughsimpson closed 1 month ago

hughsimpson commented 2 months ago

Pull Request Checklist

Fixes

Whilst mocking a trait or class with a method that took a type parameter worked in scala 3 for many cases, it did not work when the type parameter was used as the input for a function arg to that method. The newly-added test case failed in those instances (i.e. def p[T]) with the following:

[error] 43 |    val mockedTrait = mock[Foo]
[error]    |                               ^
[error]    |                               Found:    (t : Seq[Toot] => Seq[String])
[error]    |                               Required: Seq[?] => Seq[String]
[error]    |
[error]    | longer explanation available when compiling with `-explain`

This is a regression from scala 2

Purpose

This pr casts the args when passing them to the mock method implementation, which avoids the above error.

Background Context

This seemed the least intrusive way of getting the new test case to work

hughsimpson commented 2 months ago

@barkhorn anything I can/should do on this pr to help it on its way?

barkhorn commented 1 month ago

hey, I think @goshacodes should review this. Happy to do the admin bits but i'm not that active on the project anymor

goshacodes commented 1 month ago

Hi, looks good, lets merge