-
Notifications
You must be signed in to change notification settings - Fork 100
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
only cast null constructor args for primitives #520
only cast null constructor args for primitives #520
Conversation
Hi, thank you for your contribution! Could you please add more test cases before we merge it?
class WithOption(opt: Option[Int]) class WithInt(int: Int) class WithInt(int: String) class WithC[C[_]](foo: C[Int])
class WithC[A](foo: A) |
Edit: The following now works:
The last thing left that doesn't compile but should is
This is a progression from scalamock 5, where most of this didn't work. Original message below: The good: The following are fine in this MR:
The bad: none of the following compiles:
the
I expected/hoped that #517 would fix that, which I merged in. How would you like to move forward? I can make sure there is a clean history on rebase, and mark the failing cases with ignored tests. Would that allow us to move forward with this? |
dabe3b1
to
555ab0c
Compare
before, we tried to cast applied types to the type arguments, to capture context bounds. That fails for simple generic types that then get cast to the wrong type. However, that's all unnessecary: the only nulls we need to cast are primitives, which can't be passed as null. Anyting else doesn't need a cast at all
9f20f92
to
b2cf100
Compare
b2cf100
to
cf3ab78
Compare
Will the following example work?
Now I'm getting an error like this.
UPD: For scala 2.13 |
I'm trying to fix that too @segery -- things seem a bit bumpy at the moment Edit: yes, that's fixed in this MR, but only for scala 3. |
Some of the new tests that pass for scala 3, fail for scala 2.12 and 2.13. To my surprise, that doesn't seem new: scalamock 5.2.0 shows the same problem: https://scastie.scala-lang.org/aTyLV1LpQ0WEfRJU6s2x5Q Therefore I moved the tests to a scala 3 specific suite. That, as far as I'm concerned, makes this MR ready for review again. |
Looks good. @barkhorn, merge it pls |
before, we tried to cast applied types to the type arguments, to capture context bounds. That fails for simple generic types that then get cast to the wrong type. However, that's all unnessecary: the only nulls we need to cast are primitives, which can't be passed as null. Anyting else doesn't need a cast at all
Pull Request Checklist
Fixes
Fixes #519
Purpose
Fix mocking classes with generic parameters. Before, mocking
class Foo(x: Option[Int])
failedBackground Context
simplifying the casts by only doing them when needed simplifies thing significantly
References