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.

Summoning Mirror for ADT defined in trait

See original GitHub issue

Compiler version

scala-3.1.0-RC1-bin-20210817-f27c250-NIGHTLY (I tried to use the most recent I could find as I thought there’s a chance that https://github.com/lampepfl/dotty/pull/11686 might have fixed this as it’s in a similar area. Not entirely sure if that made it into this nightly or not)

Minimized code

import scala.deriving.Mirror

class Scope extends IListDefn {

  type Of = Mirror { type MirroredType[X] = IList[X]; type MirroredMonoType = IList[Any] ; type MirroredElemTypes[_] <: Tuple }

  val M = summon[Of]
}


trait IListDefn {
  sealed trait IList[A]
  case class INil[A]() extends IList[A]
  case class ICons[A](h: A, t: IList[A]) extends IList[A]
}

Output

[error] -- Error: /private/tmp/scala/Minimization.scala:7:20 ---------------------------
[error] 7 |  val M = summon[Of]
[error]   |                    ^
[error]   |no implicit argument of type Scope.this.Of was found for parameter x of method summon in object Predef
[error] one error found

Expectation

Compilation should succeed (and does if you move the IList definition out of the trait and up to top-level)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Aug 29, 2021

Yes, for the moment this is simply out of spec. We generate mirrors only for statically accessible classes. I would advise to go slowly here and make absolutely sure that each generalization step can be made without negative consequences.

1reaction
milessabincommented, Aug 18, 2021

@bishabosha is there any chance we could tweak the accessibility test before 3.1?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type Class Derivation
Sum types (i.e. sealed class or traits with product children, and enums) have mirrors which are subtypes of Mirror.Sum . For the Tree...
Read more >
Type Class Derivation
Product types (i.e. case classes and objects, and enum cases) have mirrors which are subtypes of Mirror.Product . Sum types (i.e. sealed class...
Read more >
quotes.reflect.memberType can return ClassInfo #15159
I'm trying to summon a typeclass instance for each child class of a sealed trait. So far I've got the following code (here...
Read more >
Automatically Deriving Typeclass Instances in Scala 3
For now, the most important part of the Mirror is the breakdown between Sum and Product . Our BinaryTree is an Algebraic Data...
Read more >
circe/circe - Gitter
I'm trying to take a Json circe object in Java and call .as(ObjectDefinedInScalaW@JsonCodeAnnotation) . But obviously Java doesn't have implicit decoders. Is my ......
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