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.

scala 3 sealed trait object can't be referenced from scala 2

See original GitHub issue

Compiler version

3.1.3 with 2.13.8 (it doesn’t occur with 3.1.2 or 3.0.2 together with 2.13.8)

Minimized code

This requires a multi project sbt build with one small file in each project. The easiest reproduction is from https://github.com/johnduffell/tasty-tuple-issue

git clone git@github.com:johnduffell/tasty-tuple-issue.git
sbt scala2/compile

A summary is that with this code in scala 3, AValue can’t be referenced from scala 2

sealed trait Scala3ADT

object Scala3ADT {
  case object AValue extends Scala3ADT
}

Output

compiler error: Unsupported Scala 3 generic tuple type scala.Tuple in bounds of type MirroredElemTypes; found in scala.deriving.Mirror.<refinement>.

Full output is:

[info] welcome to sbt 1.7.1 (AdoptOpenJDK Java 1.8.0_275)
[info] loading settings for project global-plugins from plugins.sbt ...
[info] loading global plugins from /Users/john_duffell/.sbt/1.0/plugins
[info] loading project definition from /Users/john_duffell/code/tasty-tuple-issue/project
[info] loading settings for project root from build.sbt ...
[info] set current project to tasty-tuple-issue (in build file:/Users/john_duffell/code/tasty-tuple-issue/)
[info] compiling 1 Scala source to /Users/john_duffell/code/tasty-tuple-issue/scala3/target/scala-3.1.3/classes ...
[info] compiling 1 Scala source to /Users/john_duffell/code/tasty-tuple-issue/scala2/target/scala-2.13/classes ...
[error] Unsupported Scala 3 generic tuple type scala.Tuple in bounds of type MirroredElemTypes; found in  scala.deriving.Mirror.<refinement>.
[error] one error found
[error] (scala2 / Compile / compileIncremental) Compilation failed
[error] Total time: 6 s, completed 17-Aug-2022 22:56:25

Expectation

The code should compile correctly.

Notes

It appears that scala.Tuple is expected to be erased by the scala 3 compiler, so it wouldn’t be found by scala 2 tasty reader. However it appears that the Mirror created for sealed traits has a member with Tuple as a type contstraint, which then seems to not be erased and trips things up.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
johnduffellcommented, Aug 18, 2022

thanks, I will revert to 3.1.2 until there is 2.13.9 out. This was a massive head scratcher!

1reaction
bishaboshacommented, Aug 18, 2022

@johnduffell you can always get a debug trace for tasty reading if you use the flag -Ydebug-tasty on the scala 2 compiler, adding -Ydebug flag at the same time will trace even more fine grained detail

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a sealed trait? - Stack Overflow
A sealed trait can be extended only in the same file as its declaration. They are often used to provide an alternative to...
Read more >
Unexpected `Illegal cyclic reference` error since Scala 3.1.2
Problem found when migrating sangria to Scala 3. Compiler version 3.1.3-RC4 Runs correctly in 3.1.1, broken since 3.1.2, dottyCompileBisect gave me 40ae7ee ...
Read more >
Scala | Sealed Trait - GeeksforGeeks
Sealed traits can only extend in the same source file as of sub-types- In above example, we have another class python in another...
Read more >
Traits | Tour of Scala
Classes and objects can extend traits, but traits cannot be instantiated and therefore have no parameters. Defining a trait. A minimal trait is...
Read more >
Open Classes - Scala 3 - EPFL
It is treated as a normal identifier unless it is in modifier position. An open class cannot be final or sealed . Traits...
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