question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassCastException when summoning Mirror for hierarchical sum compiled by 3.0.x

See original GitHub issue

Compiler version

3.1.0

Minimized code

compile with Scala 3.0.2 to out dir

sealed trait Top
object Top // companion is necessary

case class Middle() extends Top with Bottom
sealed trait Bottom extends Top

compile with Scala 3.1.0 and with out on classpath

val m = summon[deriving.Mirror.SumOf[Top]]

Output

runtime error:

java.lang.ClassCastException: Top$ cannot be cast to scala.deriving.Mirror$Sum
  ... 28 elided

This happens because Top is an eligible sum, and it has a companion object (which if compiled by Scala 3.1.0 would extend deriving.Mirror.Sum), so the companion object is used as the mirror and is cast to Sum.

Expectation

prevent summoning mirrors for hierarchical sums with companion objects compiled before 3.1.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Oct 20, 2021

Currently, the community build rebuilds all transitive dependencies from sources, this is a great showcase of why we may want to also have a version of the community build which keeps the binary dependencies.

1reaction
bishaboshacommented, Oct 20, 2021

I’d say don’t use the companion object as the mirror if it doesn’t extend Mirror.Sum, but rather summon a local mirror. Any reason that can’t be made to work?

This sounds very reasonable to me.

Summarising a Slack discussion: @dwijnand and @julienrf also asked if we can check if the companion is a subtype of Mirror.Sum, I said this is not possible with code compiled from source, as mirror synthesis happens too early in the compiler currently, so @dwijnand suggested that if we can check if a type is a compiled dependency, then check that its companion extends Mirror.Sum, else keep the current behavior.

this change can be implemented in SymUtils.useCompanionAsMirror

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scala 3: How do you extract the names of elements from a ...
I think there is a bug, since I have been able to extract element labels from Product mirrors, but not Sum s. It...
Read more >
Advisory Board 2021 Q4 Report - Scala Center
Mirror.SumOf[T]`, where `T` is a hierarchical sum type compiled by Scala 3.0.x, could cause a ClassCastException). To fix this.
Read more >
java array in methods Code Example
String intArrayString = Arrays.toString(intArray);. 3. 4. // print directly will print reference value. 5. System.out.println(intArray);.
Read more >
mondrian-users Mailing List for Mondrian (Page 2)
hello, I have downloaded the mondrian 2.3.2 source code and compiled in my pc. ... This should mirror an SQL report: SELECT SUM(oi.unit_price...
Read more >
https://huggingface.co/jeniya/BERTOverflow/commit/...
+/ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +: +; +< += +> +? +@ +A +B +C +D +E...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found