-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Extension in implicit object can no longer be used #22920
Comments
For context, that implicit object was deleted from
With |
cc @mbovel |
In cases like this, it helps to supply the implicit argument manually and see what happens. First, there is no @main def Test = {
import delay.{Async, syntax}
val initializeOutbound: Async[Any, String] = ???
syntax.run(initializeOutbound):
case Success(target) => ???
case Failure(exception) => ???
} And the compiler responded with -- [E172] Type Error: i22920.scala:20:32 ---------------------------------------
20 | syntax.run(initializeOutbound):
| ^
|No implicit search was attempted for parameter ctx of method run in object syntax
|since the expected type Ctx is not specific enough
|
|where: Ctx is a type variable
1 error found And that makes also sense. There is no specific The original error message is not great, but given how botched this example is, I don't think it's a good idea to invest a lot of time to tweak it. |
cc @rmgk |
The extension is in implicit scope because in a prefix of If the type is Writing the call explicitly, for debug, it finally says I'm looking at a ticket about improving The suggestions are tricky, but also a beloved feature of Dotty (as I gather from social media). |
The issue title is quite misleading. I minimized the example further to: object delay {
class Contravariant[-Ctx]
inline def run[Ctx](contravariant: Contravariant[Ctx])(using inline ctx: Ctx): Unit = ???
}
@main def Test = {
import delay.*
val anyValue: Contravariant[Any] = ???
delay.run(anyValue)
} So it seems to me that this combination of inline and a contravariant type somehow did not trigger the specificity check for summoning the implicit value. When I wrote the code, I vaguely remember that I was wondering why it would work when not specifying the context, then realizing that it likely would just use some random implicit value. The old behaviour is kinda useful in this “can just not specify a context” way. My tests indicate that specifying the context as part of the run method is sufficient (i.e., I tried this patch for the failed project: … the compiler crash is more likely due to the macros. I’ll investigate if I find time (likely only if the issue comes up again) |
To maybe comment on the error message, the message seems to be due to some combination of type inference, and implict parameters on extension methods, and can be triggered with a minified:
I think the only unusual bit about this code is that using It really just seems to be an unfortunate interaction with the bit of logic that decides that |
It's looking for anything it can convert to the required type of the missing arg. I'm not sure if it refuses to search for TIL the explicit using arg (below) is required even if there is a given of the required type. That is, there is no sense in which the "exact" type satisfies the implicit param without asking if it conforms, which is just to ask The extra import is not needed. Also, object delay {
class Box[A]
extension [A](box: Box[A]) def run(using A): Unit = ???
}
@main def Test = {
import delay.Box
//import delay.{Box, run}
given any: Any = ()
val anyValue: Box[Any] = ???
anyValue.run(using any)
}
|
Based on OpenCB failure in
rescala-lang/rescala
- build logsCompiler version
Last good release: 3.7.1-RC1-bin-20250328-d519790-NIGHTLY
First bad release: 3.7.1-RC1-bin-20250401-d0e9062-NIGHTLY
Bisect points to 4cdeb81
Minimized code
Output
Expectation
Not sure if this usage is covered by language specification. In such case it should be decided accessing extension in implicit object is an undefined behaviour. Otherwise should continue to compile
The text was updated successfully, but these errors were encountered: