Closed fmonniot closed 10 months ago
Ok, so it looks like the type inference is what causes the issue. When using methods that make use of the MethodType
type, we now have to manually provide the type. If we do not, then the compiler throw a ClassCastException
because it's expecting a MethodType
type but a NoType
is actually present. Not entirely sure yet if it's because of how the When macro is implemented, or if it's a compiler bug. Need a smaller reproducer first.
That being said, given it's a fix that can only be done by the user, I'm not sure we should upgrade to 3.3.0 yet.
Here is the stack trace of the compiler error:
I ran a code snippet on the compiler code base (snippet at the end) and found out that this bug was introduced in the commit https://github.com/lampepfl/dotty/commit/b429e6b8a76e57c1570ed93d874cf63b1f9e3a88. That being said, it is fairly possible that this commit only exhibit the issue (cause of the added cast) as opposed to be the root cause of it.
Confirmed that the commit only made the error apparent. When compiling the snippet under 3.2.2 with the -Ycheck:all
parameter, then we have the same error even on 3.2.2. I'll try to minimize the when
macro to reproduce this issue.
Thanks for the investigation! I've minimized this to:
class MockFunction1[T1]:
def expects(v1: T1 | Foo): Any = ???
def expects(matcher: String): Any = ???
def when[T1](f: T1 => Any): MockFunction1[T1] =
???
class Foo
def main =
val f: Foo = new Foo
when((x: Foo) => "").expects(f)
I'm working on a fix currently.
Oh nice! I didn't had time to work on side projects over the past two weeks, thanks for taking the time to write a minimizer!
Given it's the first LTS, we should try to stay on it. Although given metaprogramming is one aspect that make progress relatively quickly, maybe we will jump on a feature release (for example if the implicit/using modified is made accessible when creating functions)