Expr.summon won't compile with dynamically created Type
See original GitHub issueCompiler version
3.0.0-RC1
Minimized code
import scala.quoted.*
def x(using Quotes): Unit =
import quotes.reflect._
val t = TypeRepr.of[Int].asType
Expr.summon(using t)
Output
[error] -- [E007] Type Mismatch Error: /home/golly/projects/public/univeq/univeq/shared/src/main/scala-3/japgolly/univeq/internal/bug.scala:6:20
[error] 6 | Expr.summon(using t)
[error] | ^
[error] |Found: quoted.Type[?1.CAP]
[error] |Required: quoted.Type[T]
[error] |
[error] |where: ?1 is an unknown value of type scala.runtime.TypeBox[Nothing, AnyKind]
[error] | T is a type variable with constraint
Expectation
It should compile.
Workaround is to append .asInstanceOf[Type[Any]]
like this:
import scala.quoted.*
def x(using Quotes): Unit =
import quotes.reflect._
val t = TypeRepr.of[Int].asType.asInstanceOf[Type[Any]]
Expr.summon(using t)
Manual testing confirms that the type parameter being Any doesn’t affect the result, (as one would expect) the result is purely driven by the Type
instance.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Scala3 macro summon typeclass instance of a TypeTree (no ...
Implicits.search can be used to summon implicit instance if there is no type arg avaiable for Expr.summon val valDefTree = cf.tree.
Read more >Scala 3 macros tips & tricks - SoftwareMill
Typechecking and summoning givens Thus we often end up using givens within a macro. A given can be summoned on-demand using Expr. summon[ ......
Read more >intro to Scala 3 macros - eed3si9n
So the general process is that we will capture either the term-level parameters or types, and return a typed abtract syntax tree called...
Read more >FAQ | Macros in Scala 3
How do I summon an expression for statically unknown types? You can summon an expression from either a TypeRepr or a Type as...
Read more >Macros - Scala 3
Splicing takes expressions of type Expr[T] to expressions of type T and it takes ... But it will neither create nor remove quotes...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If there you have a
Type[_]
useIf you have a
TypeRepr
useI believe it should work with