Skip to content

Derive methods with extra context parameters #11651

Open
@nicolasstucki

Description

@nicolasstucki

Compiler version

3.0.0.RC-1

Minimized example

There is no way to add extra contextual parameters derived class.

For example we if we have derivation for the following

class MyToExpr[T]
object MyToExpr:
  inline given derived[T](using inline m: Mirror.Of[T], inline t: Type[T]): MyToExpr[T] =
    ${ q ?=> derivedExpr('m, 't)(using q, Type.of[T]) }

we need to explicitly write each given instance to be able to add the Type and Quotes contextual parameters

  sealed trait Opt[+T]
  object Opt:
    given [T: Type: MyToExpr](using Quotes): MyToExpr[Opt[T]] = MyToExpr.derived

  case class Sm[T](t: T) extends Opt[T]
  object Sm:
    given [T: Type: ToExpr](using Quotes): MyToExpr[Sm[T]] = MyToExpr.derived

  case object Nn extends Opt[Nothing]:
    given (using Quotes): MyToExpr[Nn.type] = MyToExpr.derived

In this example the Quotes in required to generate the Type within the given definitions of Opt, Sm and Nn.

Full 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