scalameta / mdoc

Typechecked markdown documentation for Scala

Home Page:https://scalameta.org/mdoc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Mirror` resolution fails in presence of extension methods

arainko opened this issue · comments

sbt: 1.7.1
sbt-mdoc: 2.3.2
Scala: 3.1.3

The issue:

```scala mdoc
import scala.deriving.*

final case class Person(firstName: String, lastName: String, age: Int)
final case class PersonButMoreFields(firstName: String, lastName: String, age: Int, socialSecurityNo: String)

final class AppliedBuilder[Source, Dest](appliedTo: Source) {
  def transform(config: BuilderConfig[Source, Dest]): Dest = ???
}

extension [Source](value: Source) {
  def into[Dest]: AppliedBuilder[Source, Dest] = AppliedBuilder(value)
}

final class BuilderConfig[Source, Dest](using Source: Mirror.ProductOf[Source], Dest: Mirror.ProductOf[Dest])

val person = Person("Jerry", "Smith", 20)

def withoutExtension = 
  AppliedBuilder[Person, PersonButMoreFields](person).transform(BuilderConfig()) // compiles

def withExtensionNoInference = 
  person.into[PersonButMoreFields].transform(BuilderConfig[Person, PersonButMoreFields]()) // compiles

def withExtension = 
  person.into[PersonButMoreFields].transform(BuilderConfig()) 
  /* no implicit argument of type deriving.Mirror.ProductOf[App.this.Person] was found for parameter Source of constructor BuilderConfig in class BuilderConfig */
  
```

The problem seems to appear as soon as we introduce an 'indirect' Mirror (by using BuilderConfig as demonstrated above) in addition to going through an extension method.

As a workaround we can annotate the types and then it's all fine and dandy but in my real world scenario the inference of these arguments is crucial because they are not the only ones there.
I've also tried switching to mdoc:reset-object because dotty is sometimes not very keen on generating mirrors for local classes but that also failed with the same error.

The snippet itself compiles outside of mdoc: https://scastie.scala-lang.org/aQhI34EpQv2WeQNiz6ll6g

Thanks for reporting! I tried the snippet in the Metals worksheets (which uses mdoc underneath), but that seemed to work.

Could you confirm if this a problem with the newest 2.3.3 version of mdoc?

Welp, that's embarassing 😸 It seems to be working properly on 2.3.3. I'll close the issue in shame 🥲

No worries, I am glad this is already fixed 😅