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

Failed to derive mirror in trait with self type #18918

Closed
Anghammar opened this issue Nov 14, 2023 · 5 comments · Fixed by #19083
Closed

Failed to derive mirror in trait with self type #18918

Anghammar opened this issue Nov 14, 2023 · 5 comments · Fixed by #19083

Comments

@Anghammar
Copy link

Compiler version

3.3.0

Minimized code

trait SuperTrait {
  sealed trait InnerTrait
  case class Foo() extends InnerTrait
}

trait OtherTrait

trait TraitWithSelfType extends SuperTrait { this: OtherTrait =>
  summon[deriving.Mirror.Of[Foo]]
  summon[deriving.Mirror.Of[InnerTrait]]
}

object Implementation extends TraitWithSelfType, OtherTrait {
  summon[deriving.Mirror.Of[Foo]]
  summon[deriving.Mirror.Of[InnerTrait]]
}

Output

-- [E172] Type Error: DerivingMirrorBug:10:40 ----------------------------------
10 |  summon[deriving.Mirror.Of[InnerTrait]]
   |                                        ^
   |No given instance of type deriving.Mirror.Of[TraitWithSelfType.this.InnerTrait] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[TraitWithSelfType.this.InnerTrait]:
   |	* trait InnerTrait is not a generic product because it is not a case class
   |	* trait InnerTrait is not a generic sum because its child class Foo is not accessible to call site value <local TraitWithSelfType>
1 error found

Expectation

summon[deriving.Mirror.Of[InnerTrait]] fails inside of TraitWithSelfType, but no of the other three summons fails. I'm not 100% sure this is actually a bug, but since OtherTrait does not actually do anything it sure seems like it. If it in fact works as intended, I would appreciate a short explanation why.

@Anghammar Anghammar added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 14, 2023
@WojciechMazur WojciechMazur added stat:needs spec area:typeclass-derivation and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 14, 2023
@bishabosha
Copy link
Member

given that we can call Foo() from inside TraitWithSelfType it would seem that it is accessible, so maybe that check needs investigation

@Anghammar
Copy link
Author

I just now realised I accidentally used the compiler version 3.3.0, but I have verified that the same issue exists on 3.3.1.

@EugeneFlesselle
Copy link
Contributor

@bishabosha when checking if we have access through inheritance, we first get the classSymbol of the SingletonType.
But in the case above, (TraitWithSelfType.this : OtherTrait & TraitWithSelfType).parentSymbol == NoSymbol because of the ambiguous superclasses.

I tried this fix, but this this neg test also passes as a result:

class Outer2 {
  sealed trait Item
  case object A extends Item
}
def testOuter2 =
  // discussion point: should we allow this, or only allow singleton prefix?
  val m_Outer2_Item = summon[Mirror.Of[Outer2#Item]] // error: Item is not accessible from m_Outer2_Item

@bishabosha
Copy link
Member

should we allow this, or only allow singleton prefix?

Prefixes should only be valid paths so yeah all singleton types

@michelou
Copy link
Contributor

@bishabosha Candidate for a backport ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants