scala-macros

    3熱度

    1回答

    我隔壁班的結構: trait SomeType trait Root { val allMySomeTypes: Seq[SomeType] } class Child extends Root { object MyType1 extends SomeType {...} object MyType2 extends SomeType {...} }

    1熱度

    1回答

    我正在研究斯卡拉宏,我想匹配Symbol到List[T]的類型,其中T是給定的Type。我已經有了T類型參數的Type對象。 很容易得到的List[_]類型對象: val listType = c.weakTypeOf[List[_]] 這個我已經可以檢查typeSignature sourceParam.typeSignature match { case paramType if

    1熱度

    1回答

    編輯:我發現我的錯誤 - 有在quasiquotes我遞歸的情況下,錯誤是導致它返回一個畸形的序列 我想創建一個宏,將案例類T轉換爲updateMap: Map[String, (play.api.libs.json.JsValue) => Try[(T) => T]](How to use scala macros to create a function object (to create a

    1熱度

    1回答

    編輯:我已經解決了這個問題 - 我被錯誤地呼喚.map(f => f.typeSignature.asInstanceOf[TypeRef].args.head)上recursiveOpt,這意味着field.name是給我在我的copy錯誤的字段名方法。我已經刪除了map,現在一切正常。 我正在寫一個宏,它將爲案例類創建更新方法的映射,例如, case class Inner(innerStr:

    9熱度

    3回答

    鑑於how difficult it is to know whether an arithmetic final val expression will be compiled to a compile-time constant, and how easy it is to accidentally break compile-time-ness ...... 誰能想到一個簡單的方法來驗證,在

    0熱度

    1回答

    我想使用宏來爲case類生成setter。例如: case class Person(name: String, age: Int) Macro.mkSetter[Person, String]("name") : Person => String => Person 我嘗試了以下實現,但我不斷收到以下 error: scala: Error: Unknown source file: [

    5熱度

    1回答

    我想計算一個Scala類的包名。 以下作品的代碼,但似乎有點冗長 def packagename(cls:ru.ClassSymbol):String = { def innerPackageName(cls:JavaUniverse#Symbol):List[JavaUniverse#Name] = { if(cls.owner != null && cls.owner.i

    1熱度

    1回答

    我試圖通過使用隱式宏來收集範圍中存在的所有標識符,但我無法找到找到它們的優雅方法。 val endPos = c.enclosingPosition.endOrPoint val mNames = c.enclosingMethod .collect {case v: ValDef => v} .filter(_.pos.start > endPos)

    3熱度

    1回答

    我剛開始玩宏,想實現從this class Queryable[T] { def map[U](p: T => U): Queryable[U] = macro QImpl.map[T, U] } object QImpl { def map[T: c.WeakTypeTag, U: c.WeakTypeTag] (c: Context) (p: c.Expr[T

    2熱度

    2回答

    我試圖用Context#eval方法來評估宏觀內的Expr: [error] /home/falcone/prg/sbt-example-paradise/core/src/main/scala/Test.scala:20: exception during macro expansion: [error] scala.tools.reflect.ToolBoxError: reflective