Open goshacodes opened 1 month ago
@goshacodes how exactly to reproduce the tuples from your generated code example?
I'll return with example today
object Example:
inline def example: Unit =
${ ExampleMacro.example }
object ExampleMacro:
def example(using quotes: Quotes): Expr[Unit] =
import quotes.reflect.*
val term = ValDef.let(
Symbol.spliceOwner,
List('{5}.asTerm, '{"foo"}.asTerm)
) { refs =>
refs.foldRight[Term]('{ EmptyTuple }.asTerm) { (el, acc) =>
Select.unique(acc, "*:")
.appliedToTypes(List(el.tpe, acc.tpe))
.appliedToArgs(List(el))
}
}
'{println(${Expr(term.show(using Printer.TreeAnsiCode)})}
output:
{
val x: scala.Int = 5
val `x₂`: java.lang.String = "foo"
scala.Tuple$package.EmptyTuple.*:[x.type, scala.Tuple$package.EmptyTuple.type](`x₂`).*:[x.type, scala.*:[x, scala.Tuple$package.EmptyTuple]](x)
}
expected:
(x, x2)
or at least x *: x2 *: EmptyTuple
Compiler version
3.3.0
Output
I use Printer.TreeAnsiCode and Printer.TreeShortCode. and tuple
In generated code tuples looks something like this:
Which is very hard to read
Expectation
When should look like this