Repository navigation
Don't infer implicits from non-accessible companion - #25367
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
There are some CI failures, though. |
Yes, i'll fix them. Thanks for the review! |
|
I believe the test case in that PR should not compile, the compiler infers the implicit argument for
My PR will likely lead to compilation failures in the community build, but that should be addressed by updating the project's source code. |
There was a problem hiding this comment.
-- [E172] Type Error: tests/neg/i22593b/Test.scala:3:10 ------------------------
3 | jam.brew // error
| ^
|No given instance of type jam.internal.JamConfig was found for parameter config of method brew in package jam
|
|One of the following imports might fix the problem:
|
| import jam.defaultJamConfig
| import jam.internal.defaultJamConfig
|
The error there looks good now (previously without that reverted PR it was some incoherent type error).
|
So this should be good to go. Though perhaps we should wait for a minor, because I expect it will cause some existing code to fail to compile. @Gedochao Can we run the community build before merge to check? |
Based on the community build results, I guess we could think whether this should go now in 3.8.3, or wait for 3.10. |
|
Comparsion against 3.8.3-RC1 Note: Red background - new failures, yellow background existing failures present in previous compiler version, there's a switch for filtering by failures reason, and to filter out only new failures, but vibed dashboard seems not to support combination of these filters. It seems to introduce regressions related to implicit or typer (missing implicit conversions?) |
|
Seems like we'll wait for 3.10 with this (and hopefully address the regressions in the meantime) |
Yes, the PR changes implicit search to discard candidates found in non-accessible companions. As a small example, this used to compile, but now it fails with a type mismach error: object t {
class C
private object C { implicit def c2s(c: C): String = "" }
}
val c = new t.C()
def m: String = c // found: C, required: String(An explicit reference to the implicit Maybe it's possible to turn this into a deprecation warning in 3.8 / 3.9, that would be helpful. The problem is that the type mismatch / implicit not found errors don't make it easy to tell how the code used to compile before, which non-accessible implicit was inferred. |
|
Deprecation first in PR #25516. I changed this PR to revert the deprecation and change the implicit resolution. |
7b12aea to
8d4868a
Compare
06e8097 to
2b2ca70
Compare
|
This can now be merged since main is 3.10, correct? (Just double checking since there was a mention of regressions in the discussion here) |
Implicits found in the companion object of a type should not be inferred if the companion object is not accessible.
|
Rebased. |
|
Linking repository with 20 failures in OpenCB due to this change, minimized with LLMs: https://github.com/WojciechMazur/scala3-non-accessible-companion-25367 Also we'd need to address it as one of core changes of 3.10 - even right now it seems to have large impact on the community. At current point it seems we'd need help and informative campaign for the Scala OSS as new releases of core libraries would be required, and ideally should land before 3.10.0 To consider: maybe under |
|
Yeah, you're right. If someone wants to upgrade to 3.10 but they use a library that has such a "broken" API, they are blocked. apache/pekko-http#1056 |
…rox from FunProtoTyped (#25662) Reproduction case for #24824 as issue was solved by #25367 (pass caller context - details: #24824 (comment)). ~~Address #24824: preserve `FunProtoTyped` in `wildApprox` and `FunProtoTyped.map` to avoid assert from `collectParts` that leading to a crash~~ ## How much have you relied on LLM-based tools in this contribution? moderately: I feed LLM with relevant issues, PRs; reiterated over proposed solutions, ~then switched to work done by @Alex1005a as he had more mature solution~ ## How was the solution tested? Tested locally added reproduction case: ```shell sbt --client "testCompilation 24824" ``` --------- Signed-off-by: Piotr Paradzinski <dancingwithopenheart@gmail.com> Co-authored-by: alex <asafofalexander@gmail.com>
Scala 3.10 no longer infers implicits from companions that are not accessible from the call site (scala/scala3#25367). InitLast's companion was private[prometheus4cats], so every chained .label[...] call in user code failed with 'No given instance of type InitLast.Aux[...]'.
Implicits found in the companion object of a type should not be inferred if the companion object is not accessible.
Fixes #25347
How much have your relied on LLM-based tools in this contribution?
Asked it to forward-port scala/scala#11215, but its attempt to fix it was in the wrong spot. So the fix is manual, I used the unit test file it created.
How was the solution tested?
The test passes, we now get a type mismatch error instead of the non-accessible implicit being inferred.
I tried separate compilation with two
scalaccalls in sbt, but that did something strange, I ran into a different problem.I tried
scala3-bootstrapped/publishLocalto test it but that failed too withI feel a bit out of time to look further into this right now.