Skip to content

Allow to implement abstract inline methods for type classes in quotes #22516

Open
@goshacodes

Description

@goshacodes

Hi! I want to implement abstract inline method in macro and it fails. The only way I can derive this is via quotation (there are some compile time configuration, which properly can be used only in macro), so it would be really great to allow this.

Compiler version

3.3.5 and 3.6.3

Minimized code

trait TokenWriter

trait JsonWriter[A]:
 inline def write(value: A, tokenWriter: TokenWriter): Unit

object JsonWriter:
 inline def derived[A]: JsonWriter[A] = ${ derivedMacro[A] }

def derivedMacro[A](using quotes: scala.quoted.Quotes): scala.quoted.Expr[JsonWriter[A]] =
  import quotes.reflect.*
 '{
     new JsonWriter[A]:
       inline def write(value: A, tokenWriter: TokenWriter): Unit = ()
  }

Output

[error] 308 |          inline def write(value: T, tokenWriter: TokenWriter): Unit =
[error]     |                     ^
[error]     |                     inline def cannot be within quotes

Expectation

Compiles

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