Skip to content

Macro type class derivation (inline definition) #11650

Open
@nicolasstucki

Description

@nicolasstucki

Compiler version

3.0.0.RC-1

Minimized example

There is no way to derive automatically an inline given definition.

enum Opt[+T] derives Show:
  case Sm[+T](x: T) extends Opt[T]
  case Nn extends Opt[Nothing]

class Show[T]
object Show:
  inline def derived[T](using deriving.Mirror.Of[T]): Show[T] = ???

the previous code derives

object Opt:
  given derived$Show[T](implicit x$0: Show[T]): Show[Opt[T]] = Show.derived[Opt[T]](...)

but in some cases we want do derive

object Opt:
  inline given derived$Show[T](implicit x$0: Show[T]): Show[Opt[T]] = Show.derived[Opt[T]](...)

Why?

  • Summon extra implicits using summonInline or Expr.summon
  • Genrerate shorter/faster code

Workarround

Write the given definition manually and not use derives

object Opt:
  inline given show[T](implicit x$0: Show[T]): Show[Opt[T]] = Show.derived[Opt[T]](...)

Example: see #11647

Expectation

We should have a way to easily derive such definitions

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions