You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importscala.quoted.*defwithGiven[T:Type](values: List[Expr[Any]])(result: Quotes?=>Expr[T])(usingQuotes):Expr[T] =
values matchcase'{ $x: t } :: values =>'{ givent= $x; ${ withGiven(values)(result) } }
case _ =>
result
defwithGivenInt(x: Expr[Int])(usingQuotes) =
withGiven(x ::Nil)(Expr.summon[Int].get)
inlinedefwithInt(inlinex: Int) =${withGivenInt('x)}
Output
scala> withInt(42)
--Error:----------------------------------------------------------------------1|withInt(42)
|^^^^^^^^^^^|Exception occurred while executing macro expansion.
|java.util.NoSuchElementException:None.get
| at scala.None$.get(Option.scala:627)
| at scala.None$.get(Option.scala:626)
| at rs$line$1$.withGivenInt$$anonfun$1(rs$line$1:11)
| at rs$line$1$.withGiven(rs$line$1:8)
| at rs$line$1$.withGiven$$anonfun$1(rs$line$1:6)
| at rs$line$1$.withGiven$$anonfun$adapted$1(rs$line$1:6)
| at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:111)
| at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1571)
| at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
| at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1270)
| at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1252)
| at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1265)
| at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1270)
| at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1551)
| at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
| at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:153)
| at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:89)
| at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3279)
| at rs$line$1$.withGiven(rs$line$1:6)
| at rs$line$1$.withGivenInt(rs$line$1:11)
||----------------------------------------------------------------------------|Inline stack trace
|--------------------------------------|This location contains code that was inlined from rs$line$1:1414|${withGivenInt('x)}
|^^^^^^^^^^^^^^^^^^^----------------------------------------------------------------------------1 error found
Expectation
Symbol.asQuotes should populate the implicit scope.
Real world use-case: typelevel/cats-tagless#588
See the hack that I had to do (refs here are the implicit parameters of the method owning the quotes q):
Hi! I see the Expr.summon docs are not precise in terms of what they mean by "scope", but I always interpreted it as the scope of macro entry method. Were there any problems with using summonInline instead (which delays the summoning until after the macro is expanded)? I see it was removed.
summonInline also doesn't take into account the implicit scope of the current owner.
but I always interpreted it as the scope of macro entry method
That's how it works currently but that's a departure from normal Scala giving special semantics to macros. In a sense, quasi-quotes in Scala 2 emulated better code you would write by hand.
Compiler version
3.6.2
Minimized code
Output
Expectation
Symbol.asQuotes
should populate the implicit scope.Real world use-case: typelevel/cats-tagless#588
See the hack that I had to do (
refs
here are the implicit parameters of the method owning the quotesq
):The text was updated successfully, but these errors were encountered: