Last active
February 23, 2017 18:45
-
-
Save shyamsalimkumar/ebef43b02d5bc71320f6f6ef2c197459 to your computer and use it in GitHub Desktop.
Trying annotating a constructor parameter `class A(@field("first_field") val a: String)`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name := "scala-meta-playground" | |
version := "0.0.1" | |
scalaVersion := "2.11.8" | |
libraryDependencies += "org.scalameta" %% "scalameta" % "1.6.0" | |
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" | |
addCompilerPlugin("org.scalameta" % "paradise" % "3.0.0-beta4" cross CrossVersion.full) | |
scalacOptions += "-Xplugin-require:macroparadise" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.scalameta.invariants.InvariantFailedException: invariant failed: | |
when verifying stats.forall(((x$1: scala.meta.Stat) => scala.meta.internal.ast.Helpers.XtensionStat(x$1).isBlockStat)) | |
found that stats.forall(((x$1: scala.meta.Stat) => scala.meta.internal.ast.Helpers.XtensionStat(x$1).isBlockStat)) is false | |
where stats = List(val a: String, class A(val a: String)) | |
at org.scalameta.invariants.InvariantFailedException$.raise(Exceptions.scala:15) | |
at scala.meta.Term$Block$.internal$46(Trees.scala:80) | |
at scala.meta.Term$Block$.apply(Trees.scala:79) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$class.expand$2(Expanders.scala:116) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$$anonfun$expandNewAnnotationMacro$1.apply(Expanders.scala:181) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$$anonfun$expandNewAnnotationMacro$1.apply(Expanders.scala:181) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$class.extractAndValidateExpansions(Expanders.scala:258) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$class.expandNewAnnotationMacro(Expanders.scala:181) | |
at org.scalameta.paradise.typechecker.Namers$$anon$3.expandNewAnnotationMacro(Namers.scala:12) | |
at org.scalameta.paradise.typechecker.Namers$Namer$$anon$2.org$scalameta$paradise$typechecker$Namers$Namer$class$$anon$$maybeExpand$1(Namers.scala:396) | |
at org.scalameta.paradise.typechecker.Namers$Namer$$anon$2$$anonfun$7.apply(Namers.scala:404) | |
at org.scalameta.paradise.typechecker.Namers$Namer$$anon$2$$anonfun$7.apply(Namers.scala:404) | |
at scala.collection.immutable.Stream.flatMap(Stream.scala:489) | |
at org.scalameta.paradise.typechecker.Namers$Namer$$anon$2.maybeExpand(Namers.scala:404) | |
at org.scalameta.paradise.typechecker.Namers$Namer$MaybeExpandeeCompleter.completeImpl(Namers.scala:336) | |
at org.scalameta.paradise.typechecker.Namers$Namer$MaybeExpandeeCompleter.complete(Namers.scala:326) | |
at org.scalameta.paradise.typechecker.Namers$Namer$RichType.completeOnlyExpansions(Namers.scala:355) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$$anonfun$expandMacroAnnotations$2.apply(Expanders.scala:292) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$$anonfun$expandMacroAnnotations$2.apply(Expanders.scala:282) | |
at scala.collection.immutable.List.flatMap(List.scala:327) | |
at org.scalameta.paradise.typechecker.Expanders$Expander$class.expandMacroAnnotations(Expanders.scala:282) | |
at org.scalameta.paradise.typechecker.Expanders$$anon$1.expandMacroAnnotations(Expanders.scala:23) | |
at org.scalameta.paradise.typechecker.AnalyzerPlugins$MacroPlugin$.pluginsEnterStats(AnalyzerPlugins.scala:46) | |
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anonfun$pluginsEnterStats$1.apply(AnalyzerPlugins.scala:450) | |
at scala.tools.nsc.typechecker.AnalyzerPlugins$$anonfun$pluginsEnterStats$1.apply(AnalyzerPlugins.scala:449) | |
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:124) | |
at scala.collection.immutable.List.foldLeft(List.scala:84) | |
at scala.tools.nsc.typechecker.AnalyzerPlugins$class.pluginsEnterStats(AnalyzerPlugins.scala:449) | |
at org.scalameta.paradise.typechecker.HijackAnalyzer$$anon$2.pluginsEnterStats(HijackAnalyzer.scala:31) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:2323) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedOutsidePatternMode$1$1.apply(Typers.scala:5318) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedOutsidePatternMode$1$1.apply(Typers.scala:5318) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedOutsidePatternMode$1(Typers.scala:5317) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5353) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5360) | |
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423) | |
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:3164) | |
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgWithFormal$1(PatternTypers.scala:112) | |
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115) | |
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115) | |
at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:46) | |
at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:44) | |
at scala.collection.immutable.List.foreach(List.scala:381) | |
at scala.runtime.Tuple2Zipped$.map$extension(Tuple2Zipped.scala:44) | |
at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgsForFormals(PatternTypers.scala:115) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedArgsForFormals(Typers.scala:111) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$handleMonomorphicCall$1(Typers.scala:3470) | |
at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3495) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$98.apply(Typers.scala:4496) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$98.apply(Typers.scala:4496) | |
at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:680) | |
at scala.tools.nsc.typechecker.Typers$Typer.tryTypedApply$1(Typers.scala:4496) | |
at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4544) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4580) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5343) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5360) | |
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423) | |
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5452) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:3047) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$65.apply(Typers.scala:3151) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$65.apply(Typers.scala:3151) | |
at scala.collection.immutable.List.loop$1(List.scala:173) | |
at scala.collection.immutable.List.mapConserve(List.scala:189) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3151) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1921) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1762) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5309) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5359) | |
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423) | |
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5452) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:3047) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$65.apply(Typers.scala:3151) | |
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$65.apply(Typers.scala:3151) | |
at scala.collection.immutable.List.loop$1(List.scala:173) | |
at scala.collection.immutable.List.mapConserve(List.scala:189) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3151) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5015) | |
at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5312) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5359) | |
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396) | |
at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423) | |
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374) | |
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5448) | |
at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102) | |
at scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply$mcV$sp(Global.scala:440) | |
at scala.tools.nsc.Global$GlobalPhase.withCurrentUnit(Global.scala:431) | |
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:440) | |
at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:94) | |
at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:93) | |
at scala.collection.Iterator$class.foreach(Iterator.scala:893) | |
at scala.collection.AbstractIterator.foreach(Iterator.scala:1336) | |
at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93) | |
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1501) | |
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1486) | |
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1481) | |
at scala.tools.nsc.Global$Run.compile(Global.scala:1582) | |
at xsbt.CachedCompiler0.run(CompilerInterface.scala:116) | |
at xsbt.CachedCompiler0.run(CompilerInterface.scala:95) | |
at xsbt.CompilerInterface.run(CompilerInterface.scala:26) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) | |
at java.lang.reflect.Method.invoke(Unknown Source) | |
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:107) | |
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:53) | |
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47) | |
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply$mcV$sp(MixedAnalyzingCompiler.scala:50) | |
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50) | |
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50) | |
at sbt.compiler.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:74) | |
at sbt.compiler.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:49) | |
at sbt.compiler.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:64) | |
at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160) | |
at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160) | |
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66) | |
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64) | |
at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:32) | |
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:72) | |
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:71) | |
at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:99) | |
at sbt.inc.Incremental$.compile(Incremental.scala:71) | |
at sbt.inc.IncrementalCompile$.apply(Compile.scala:54) | |
at sbt.compiler.IC$.compileInternal(IncrementalCompiler.scala:160) | |
at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:138) | |
at sbt.Compiler$.compile(Compiler.scala:155) | |
at sbt.Compiler$.compile(Compiler.scala:141) | |
at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:879) | |
at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:870) | |
at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:868) | |
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47) | |
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40) | |
at sbt.std.Transform$$anon$4.work(System.scala:63) | |
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228) | |
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228) | |
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17) | |
at sbt.Execute.work(Execute.scala:237) | |
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228) | |
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228) | |
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159) | |
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28) | |
at java.util.concurrent.FutureTask.run(Unknown Source) | |
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) | |
at java.util.concurrent.FutureTask.run(Unknown Source) | |
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) | |
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) | |
at java.lang.Thread.run(Unknown Source) | |
[error] (test:compileIncremental) org.scalameta.invariants.InvariantFailedException: invariant failed: | |
[error] when verifying stats.forall(((x$1: scala.meta.Stat) => scala.meta.internal.ast.Helpers.XtensionStat(x$1).isBlockStat)) | |
[error] found that stats.forall(((x$1: scala.meta.Stat) => scala.meta.internal.ast.Helpers.XtensionStat(x$1).isBlockStat)) is false | |
[error] where stats = List(val a: String, class A(val a: String)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.immutable.Seq | |
import scala.meta._ | |
class Field(fieldName: String) extends scala.annotation.StaticAnnotation { | |
inline def apply(defn: Any): Any = meta { | |
val fieldName = this match { | |
case q"new $_(${Lit(tableName: String)})" => tableName | |
case _ => abort("@Field expects a string to be provided") | |
} | |
defn match { | |
case Term.Block(Seq(cls @ Defn.Class(_, name, _, _, _), companion: Defn.Object)) => | |
abort("class and object") | |
case cls @ Defn.Class(_, name, _, _, _) => abort("class") | |
case q"${name: Pat.Var.Term}" => abort("IDK") | |
case _ => abort("@Field must annotate a class' constructor params") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/scalameta/paradise/issues/16