-
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
Regression for implicit search in mixed Java/Scala compilation in scala-tsi/scala-tsi
#21303
Comments
In #21273 for revision f236ce9 (revert from main) / 1ea5485 (last commit from PR used in OpenCB) it fails with Error: -- [E172] Type Error: /build/repo/src/test/scala/com/scalatsi/EnumTests.scala:24:50
Error: 24 | val generated = implicitly[TSType[JavaEnum]]
Error: | ^
Error: |Ambiguous given instances: both method javaEnumTSType in trait JavaTSTypes and given instance given_TSType_T in trait TSTypeMacros match type com.scalatsi.TSType[com.scalatsi.types.JavaEnum] of parameter e of method implicitly in object Predef
Error: one error found |
Minimization: // Test.scala
trait TSType[T]
object TSType:
implicit def javaEnumTSType[E <: java.lang.Enum[E]]: TSType[E] = ???
inline given derived[T]: TSType[T] = compiletime.error("used given derived")
@main def Test =
summon[TSType[JavaEnum]] // error starting from 2facda0 This is as expected by the intent to prioritize givens over implicits from #19300 |
The issues will be directly affected by the changes we decide to go with in #21273. |
Yes this is ambiguous under the new rules even with #21273 or its replacement #21305. I added test cases to #21305. The problem is fixed by declaring the JavaEnum given as implicit def javaEnumTSType[E <: java.lang.Enum[E]: ClassTag]: TSType[E] = ??? instead of implicit def javaEnumTSType[E <: java.lang.Enum[E]: ClassTag]: TSNamedType[E] = ??? |
Another thing that works is to duplicate the JavaEnum implicit given javaEnumTSType[E <: java.lang.Enum[E]: ClassTag]: TSType[E] = ???
given javaEnumTSNamedType[E <: java.lang.Enum[E]: ClassTag]: TSNamedType[E] = ??? That way, we can still get a summon[TSNamedType[JavaEnum]] |
I am assigning to myself so that I can follow this and close when we decide that a mitigation is impossible. |
I am closing the issue because we already have tests (added in #21339) that verify the behavior discussed in the comments behavior. If the behavior changes the tests will fail and we can update the info on the issue. |
Compiler version
Last good release: 3.6.0-RC1-bin-20240719-af933c4-NIGHTLY
First bad release: 3.6.0-RC1-bin-20240723-46ff151-NIGHTLY
Bisect points to 2facda0
Minimized code
Output
When replacing
to
it fails with
Expectation
Should choose dedicated
javaEnumTSType
implicit and compileThe text was updated successfully, but these errors were encountered: