Questions tagged [scala-macros]
Scala macros is a facility for Scala—a general-purpose programming language—that permits compile-time metaprogramming against Scala syntax trees, from within the Scala language.
scala-macros
795
questions
1
vote
1
answer
59
views
Scala 3 macros: "dynamically" instantiating singleton objects at compile-time
I'm trying to create a macro that makes use of some objects.
Suppose I have the following definitions:
trait Foo:
def doStuff(): Unit
// in other files
object Bar extends Foo:
def doStuff() = ......
1
vote
0
answers
74
views
How to generate a companion object in Scala 3?
I have several enums where there companion object code is identical to one another.
How can I generate these companion objects where the difference between them is just the enum name?
enum Variants:
...
0
votes
1
answer
49
views
Using upickle read in Scala 3 macro
Try to write a generic macro for deserialising case classes using uPickle read in Scala 3:
inline def parseJson[T:Type](x: Expr[String])(using Quotes): Either[String, Expr[T]] = '{
try
Right(...
0
votes
1
answer
48
views
Scala 3 macro Quotes: when to use apply vs copy
I'm trying to learn how to write macros with the new Scala 3 Quotes API. In this API the various AST elements usually have two methods defined to introduce them: apply and copy where copy takes a non-...
1
vote
1
answer
77
views
how to generate fresh singleton literal type in scala using macros
I need to generate random signleton type on every macro invocation in scala 2.13
I tried something like this, but I can't change macro def return type
def randomSingletonInt: Int = macro randomImpl
...
1
vote
1
answer
93
views
exception during macro expansion: type T is not a class, play json
I'm facing this error:
exception during macro expansion:
scala.ScalaReflectionException: type T is not a class
at scala.reflect.api.Symbols$SymbolApi.asClass(Symbols.scala:284)
at scala....
0
votes
0
answers
45
views
How to extract type parameter from TypeLambda correctly?
I have a macro processing types in Scala 3, the macro is a minimized repro of an issue I am facing with airframe-surface library. The macro apparently works fine, but as soon as I add option -Xcheck-...
0
votes
1
answer
144
views
How do I update a multi project sbt build that depends on macro libraries to scala 3 in stages?
I am trying to update a large multi module repository to Scala 3 in stages.
According to the Scala 3 migration guide, there is good forward and backward runtime compatiblity, so I should be able to ...
1
vote
1
answer
67
views
Get an implicit value during macro generation for a Type
Macro generates an empty instance of a case class based on implicitly provided values for all the properties.
The current state of the solution can be found on GH:
https://github.com/atais/empty/blob/...
1
vote
1
answer
131
views
How do I hang onto an izumi.reflect.Tag?
I've been using izumi.reflect.Tag to hold onto type info, and it works great. Except when I lose that type info at some point, and then I'm not sure how to get it back. Here's what I want to do:
case ...
3
votes
0
answers
78
views
Why does this Scala 3 macros reference example of HOAS fail with "Type must be fully defined" error?
I'm new to scala 3 macros, and am trying to learn my way around them. In trying to learn how to use expression pattern matching, I tried to plug in this example from the reference [1]:
'{ ((x: Int) =&...
3
votes
0
answers
104
views
Why does this "Aux" pattern work for Shapeless but not for me?
I am trying to generate a compile-time tuple type out of a case class.
I think, I am doing exactly the same thing shapeless does with generics:
class TupleProvider[T <: Product] {
type Repr
def ...
0
votes
0
answers
46
views
How can I resolve a type provided by given in a Scala 3 macro?
I want to reflect on a class that uses Neotype (https://github.com/kitlangton/neotype/tree/main). This handy library allows you to define types that have built-in validation, and is used like this:
...
1
vote
1
answer
147
views
How can I create an enum value dynamically in Scala 3 macros?
I'm creating an enum value dynamically. I have a type of the enum (not the object itself) and a string representing a valid value, e.g. "Red" for Color.Red.
// T is Color (enum). I've ...
0
votes
0
answers
38
views
Internal error accessing enclosing macro object via a symbol of a superclass member
Sorry, this title is probably not very clear ... but that seems rather appropriate when talking about scala macros :)
So, I have a class (the ApplicationInfo thingy doesn't really matter - can be ...