Skip to content
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

[2.12] Implicits diverge on the first compilation but not in recompilation #12282

Closed
kubukoz opened this issue Dec 10, 2020 · 2 comments
Closed

Comments

@kubukoz
Copy link

kubukoz commented Dec 10, 2020

reproduction steps

See repository and open Demo.scala for instructions.

problem

The compilation fails (both in bloop and sbt) with

diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
starting with method arbContainer2 in trait ArbitraryLowPriority

but if the file containing the problematic line is successfully compiled (e.g. by commenting and uncommenting the line again), it works.

This happens on 2.12.12 but not on 2.13.0, 2.13.3 or 2.13.4 - I thought it could've been resolved by one of the issues making scala/scala-dev#405, but scala/scala#7203 (backporting them to 2.12) didn't seem to alleviate the issue.

External libraries are involved in the reproduction (both use macros, as one is shapeless and the other one interacts with magnolia) - I wasn't able to reproduce the issue without them.

Output of `-Xlog-implicits` on a clean compile
[E] [E20] src/main/scala/demo/Demo.scala:13:22
[E]       not enough arguments for method arbitrary: (implicit a: org.scalacheck.Arbitrary[(Long, Long)])org.scalacheck.Gen[(Long, Long)].
[E]       Unspecified value parameter a.
[E]       L13:   Arbitrary.arbitrary[(Long, Long)]
[E]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[E] [E19] src/main/scala/demo/Demo.scala:13:22
[E]       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
[E]       starting with method arbContainer2 in trait ArbitraryLowPriority
[E]       L13:   Arbitrary.arbitrary[(Long, Long)]
[E]                                 ^
 [E18] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbContainer is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbContainer2 in trait ArbitraryLowPriority
       L13:   Arbitrary.arbitrary[(Long, Long)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E17] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbEnum is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbContainer2 in trait ArbitraryLowPriority
       L13:   Arbitrary.arbitrary[(Long, Long)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E16] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbTuple2 is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbContainer2 in trait ArbitraryLowPriority
       L13:   Arbitrary.arbitrary[(Long, Long)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E15] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbContainer2 is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       hasMatchingSymbol reported error: diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbitrarySingleton in object Arbitraries
       L13:   Arbitrary.arbitrary[(Long, Long)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E14] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbContainer is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbitrarySingleton in object Arbitraries
       L13:   Arbitrary.arbitrary[(Long, Long)]
                                 ^
 [E13] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbEnum is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbitrarySingleton in object Arbitraries
       L13:   Arbitrary.arbitrary[(Long, Long)]
                                 ^
 [E12] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbTuple2 is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbitrarySingleton in object Arbitraries
       L13:   Arbitrary.arbitrary[(Long, Long)]
                                 ^
 [E11] src/main/scala/demo/Demo.scala:13:22
       scalacheck.this.Arbitrary.arbContainer2 is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       hasMatchingSymbol reported error: diverging implicit expansion for type org.scalacheck.Arbitrary[(Long, Long)]
       starting with method arbContainer2 in trait ArbitraryLowPriority
       L13:   Arbitrary.arbitrary[(Long, Long)]
                                 ^
 [E10] src/main/scala/demo/Demo.scala:13:22
       arbitrarySingleton is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
       hasMatchingSymbol reported error: could not find implicit value for evidence parameter of type shapeless.Witness.Aux[(Long, Long)]
       L13:   Arbitrary.arbitrary[(Long, Long)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E9] src/main/scala/demo/Demo.scala:13:22
      shapeless.this.Witness.apply is not a valid implicit value for shapeless.Witness.Aux[(Long, Long)] because:
      hasMatchingSymbol reported error: Type argument (Long, Long) is not a singleton type
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
 [E8] src/main/scala/demo/Arbitraries.scala:17:19
      scalacheck.this.Arbitrary.arbEnum is not a valid implicit value for org.scalacheck.Arbitrary[Map[K,V]] because:
      typing TypeApply reported errors for the implicit tree: type arguments [Map[K,V]] do not conform to method arbEnum's type parameter bounds [A <: Enum[A]]
      L17:       Gen.resultOf(??? : T)
                 ^^^^^^^^^^^^^^^^^^^^^
 [E7] src/main/scala/demo/Arbitraries.scala:17:19
      materializing requested scala.reflect.type.ClassTag[Map[K,V]] using scala.reflect.`package`.materializeClassTag[Map[K,V]]()
      L17:       Gen.resultOf(??? : T)
                             ^
 [E6] src/main/scala/demo/Arbitraries.scala:17:19
      arbitrarySingleton is not a valid implicit value for org.scalacheck.Arbitrary[Map[K,V]] because:
      hasMatchingSymbol reported error: could not find implicit value for evidence parameter of type shapeless.Witness.Aux[Map[K,V]]
      L17:       Gen.resultOf(??? : T)
                 ^^^^^^^^^^^^^^^^^^^^^
 [E5] src/main/scala/demo/Arbitraries.scala:17:19
      shapeless.this.Witness.apply is not a valid implicit value for shapeless.Witness.Aux[Map[K,V]] because:
      hasMatchingSymbol reported error: Type argument scala.collection.immutable.Map[K,V] is not a singleton type
      L17:       Gen.resultOf(??? : T)
                             ^
 [E4] src/main/scala/demo/Arbitraries.scala:17:19
      apply is not a valid implicit value for org.scalacheck.Arbitrary[Map[K,V]] because:
      hasMatchingSymbol reported error: magnolia: could not infer ArbitraryDerivation.Typeclass for type Map[K,V]
      L17:       Gen.resultOf(??? : T)
                 ^^^^^^^^^^^^^^^^^^^^^
 [E3] src/main/scala/demo/Arbitraries.scala:17:19
      materializing requested scala.reflect.type.ClassTag[Any] using scala.reflect.`package`.materializeClassTag[Any]()
      L17:       Gen.resultOf(??? : T)
                             ^
 [E2] src/main/scala/demo/Arbitraries.scala:17:19
      arbitrarySingleton is not a valid implicit value for org.scalacheck.Arbitrary[(K, V)] because:
      hasMatchingSymbol reported error: could not find implicit value for evidence parameter of type shapeless.Witness.Aux[(K, V)]
      L17:       Gen.resultOf(??? : T)
                 ^^^^^^^^^^^^^^^^^^^^^
 [E1] src/main/scala/demo/Arbitraries.scala:17:19
      shapeless.this.Witness.apply is not a valid implicit value for shapeless.Witness.Aux[(K, V)] because:
      hasMatchingSymbol reported error: Type argument (K, V) is not a singleton type
      L17:       Gen.resultOf(??? : T)
                             ^
[E] src/main/scala/demo/Demo.scala: L13 [E9], L13 [E10], L13 [E11], L13 [E12], L13 [E13], L13 [E14], L13 [E15], L13 [E16], L13 [E17], L13 [E18], L13 [E19], L13 [E20]
[E] src/main/scala/demo/Arbitraries.scala: L17 [E1], L17 [E2], L17 [E3], L17 [E4], L17 [E5], L17 [E6], L17 [E7], L17 [E8]
Output of -Xlog-implicits when the line is being added back
 [E8] src/main/scala/demo/Demo.scala:13:22
      scalacheck.this.Arbitrary.arbEnum is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
      typing TypeApply reported errors for the implicit tree: type arguments [(Long, Long)] do not conform to method arbEnum's type parameter bounds [A <: Enum[A]]
      L13:   Arbitrary.arbitrary[(Long, Long)]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E7] src/main/scala/demo/Demo.scala:13:22
      materializing requested scala.reflect.type.ClassTag[(Long, Long)] using scala.reflect.`package`.materializeClassTag[(Long, Long)]()
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
 [E6] src/main/scala/demo/Demo.scala:13:22
      scalacheck.this.Arbitrary.arbEnum is not a valid implicit value for org.scalacheck.Arbitrary[Long] because:
      typing TypeApply reported errors for the implicit tree: type arguments [Long] do not conform to method arbEnum's type parameter bounds [A <: Enum[A]]
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
 [E5] src/main/scala/demo/Demo.scala:13:22
      materializing requested scala.reflect.type.ClassTag[Long] using scala.reflect.`package`.materializeClassTag[Long]()
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
 [E4] src/main/scala/demo/Demo.scala:13:22
      arbitrarySingleton is not a valid implicit value for org.scalacheck.Arbitrary[Long] because:
      hasMatchingSymbol reported error: could not find implicit value for evidence parameter of type shapeless.Witness.Aux[Long]
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
 [E3] src/main/scala/demo/Demo.scala:13:22
      shapeless.this.Witness.apply is not a valid implicit value for shapeless.Witness.Aux[Long] because:
      hasMatchingSymbol reported error: Type argument Long is not a singleton type
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
 [E2] src/main/scala/demo/Demo.scala:13:22
      arbitrarySingleton is not a valid implicit value for org.scalacheck.Arbitrary[(Long, Long)] because:
      hasMatchingSymbol reported error: could not find implicit value for evidence parameter of type shapeless.Witness.Aux[(Long, Long)]
      L13:   Arbitrary.arbitrary[(Long, Long)]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 [E1] src/main/scala/demo/Demo.scala:13:22
      shapeless.this.Witness.apply is not a valid implicit value for shapeless.Witness.Aux[(Long, Long)] because:
      hasMatchingSymbol reported error: Type argument (Long, Long) is not a singleton type
      L13:   Arbitrary.arbitrary[(Long, Long)]
                                ^
src/main/scala/demo/Demo.scala: L13 [E1], L13 [E2], L13 [E3], L13 [E4], L13 [E5], L13 [E6], L13 [E7], L13 [E8]
@dwijnand dwijnand changed the title Implicits diverge on the first compilation but not in recompilation [2.12] Implicits diverge on the first compilation but not in recompilation Dec 23, 2020
@dwijnand dwijnand added this to the Backlog milestone Dec 23, 2020
@kubukoz
Copy link
Author

kubukoz commented Feb 5, 2023

FYI still happening in 2.12.17, but not in 2.13.10

@SethTisue
Copy link
Member

We don't keep open tickets on 2.12-only bugs (this one slipped through the cracks).

Does that mean we wouldn't accept a 2.12-only PR with a fix? Well, we might... it would really depend on a risk/reward assessment depending on the nature of the fix.

@SethTisue SethTisue modified the milestones: Backlog, 2.13.0 Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants