-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove uses of inline overriding inline #8601
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
Remove uses of inline overriding inline #8601
Conversation
This change was motivated by #8543 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I echo the concern about extensibility raised by @odersky :
Now it is impossible for a third-party developer to create customized assertions (I don't think there are actually any such extensions).
Maybe, the trick to use is overloading
instead of overridding
by creating a dummy implicit?
trait Assertions {
inline def assert(inline e: Boolean): Unit = println("base")
}
trait DiagramAssertions extends Assertions {
implicit object UseDiagram
inline def assert(inline e: Boolean)(implicit x: UseDiagram.type): Unit = println("derived")
}
class TestSuite extends DiagramAssertions {
assert(3 == 4)
}
@main
def Test = new TestSuite // "derived"
The overriding would be disabled with #8564. Overloading sounds like a better pattern for those use cases. It might be simpler to encode that with extension methods. I will create a prototype and add it in another PR. |
I think the cleaner solution would be to keep |
@smarter in general, with such a solution, wouldn't it mean that everyone using the base abstract type (instead of the concrete type) would get normal function calls to the abstract This could even happen in Scalatest, even though it which relies on mixins and using trait MyTestMixin { self: Assertions =>
...
assert(...) // calls the abstract method; doesn't inline (surprising behavior)
...
} Would there be a way to get an error there instead? |
This is the behavior of the brand new abstract inline methods. Precisely. |
@sjrd ah thanks, perfect. I had missed that one. |
7a88367
to
4eee851
Compare
With the changes in this PR, IDK how to migrate scalatestplus-junit: trait AssertionsForJUnit extends Assertions {
inline override def assert(inline condition: Boolean)
(implicit prettifier: Prettifier, pos: source.Position): Assertion =
${ AssertionsForJUnitMacro.assert('{condition}, '{prettifier}, '{pos}, '{""}) }
... So I think the overloading way by @liufengyun is better? |
There is an alternative using trait AbstractAssertions {
inline def assert(...): Assertion
} trait Assertions extends AbstractAssertions {
inline def assert(...): Assertion = ...
} trait AssertionsForJUnit extends AbstractAssertions {
inline def assert(...): Assertion = ...
} @ohze that is probably what you need in your use case. |
using trait SomeSuite extends org.scalatest.Suite ... Note |
Hi @ohze could you please elaborate a little bit what is the problem with the solution proposed by @nicolasstucki ? |
The main problem I think is that scalatestplus-junit depends on scalatest, so it can't be fixed without changing scalatest itself. |
@liufengyun All scalatest traits extend class Test extends WordSpec class Test extends WordSpec with Assertions |
Looks like you figured it out: giabao/scalatestplus-junit@ee3e08a, any issue with that solution ? |
No issue. |
This reverts commit 3cfd618 We will use overloading instead of overridding: scala/scala3#8601 (review)
No description provided.