Skip to content

Commit

Permalink
fixed issues with warnings in macro code
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Apr 25, 2024
1 parent 2b088c7 commit c72bd5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ private object debuggable {
private def collect(c: blackbox.Context)(treeName: String, defs: List[c.Tree], recon: List[c.Tree] => c.Tree): c.Tree = {
import c.universe._
val parsleyTy = c.typeOf[Parsley[_]].typeSymbol
val noBody = atPos(c.enclosingPosition)(q"??? : @scala.annotation.nowarn")
// can't typecheck constructors in a stand-alone block
val noConDefs = defs.flatMap {
case DefDef(_, name, _, _, _, _) if name == TermName("<init>") => None
// in addition, on 2.12, we need to remove `paramaccessor` modifiers on constructor arguments
case ValDef(Modifiers(_, _, annotations), name, tpt, x) =>
// if the type tree is not empty, then we might as well scratch out the body -- helps remove problem values!
// just to be safe, we'll also mark them as LAZY to avoid "dead code following construct"
Some(ValDef(Modifiers(Flag.LAZY, typeNames.EMPTY, annotations), name, tpt, if (tpt.nonEmpty) q"???" else x))
// must use lazy here to fix problems with nested objects, for some reason...
Some(ValDef(Modifiers(Flag.LAZY, typeNames.EMPTY, annotations), name, tpt, if (tpt.nonEmpty) noBody else x))
// FIXME: probably strip mods from all defdefs as above?
// if the type tree is not empty, then we might as well scratch out the body -- helps remove problem values!
case DefDef(mods, name, tyArgs, args, tpt, _) if tpt.nonEmpty => Some(DefDef(mods, name, tyArgs, args, tpt, q"???"))
case DefDef(mods, name, tyArgs, args, tpt, _) if tpt.nonEmpty => Some(DefDef(mods, name, tyArgs, args, tpt, noBody))
case dfn => Some(dfn)
}
val typeMap = c.typecheck(q"..${noConDefs}", c.TERMmode, silent = true) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class parsers(val x: Int) {
val q = p ~> p
lazy val r: Parsley[Char] = ~r ~> q
def s = otherParsers.a
val y = 7
val y = 8

def this(f: Float) = this(f.toInt)
def many[A](p: Parsley[A]): Parsley[List[A]] = Parsley.many(p)
Expand All @@ -38,4 +38,3 @@ object Extender extends AbsCls {
override val xs = List(7)
override def foo = 5
}

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class DebuggerUsageSpec extends ParsleyTest {
}
}

// Look, for some reason the annotation dies if it's nested, I don't know why, it's impossible to diagnose
object DebuggerUsageSpec {
@experimental @parsley.debuggable
private [parsley] object Arithmetic {
Expand Down

0 comments on commit c72bd5a

Please sign in to comment.