Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/neg-macros/delegate-match-1/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ inline def f: Any = ${ fImpl }
private def fImpl(given qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty.{_, given}
searchImplicit(('[A]).unseal.tpe) match {
case IsImplicitSearchSuccess(x) =>
case x: ImplicitSearchSuccess =>
'{}
case IsDivergingImplicit(x) => '{}
case x: DivergingImplicit => '{}
error("DivergingImplicit\n" + x.explanation, rootPosition)
'{}
case IsNoMatchingImplicits(x) =>
case x: NoMatchingImplicits =>
error("NoMatchingImplicits\n" + x.explanation, rootPosition)
'{}
case IsAmbiguousImplicits(x) =>
case x: AmbiguousImplicits =>
error("AmbiguousImplicits\n" + x.explanation, rootPosition)
'{}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/neg-macros/delegate-match-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ inline def f: Any = ${ fImpl }
private def fImpl(given qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty.{_, given}
searchImplicit(('[A]).unseal.tpe) match {
case IsImplicitSearchSuccess(x) =>
case x: ImplicitSearchSuccess =>
'{}
case IsDivergingImplicit(x) => '{}
case x: DivergingImplicit => '{}
error("DivergingImplicit\n" + x.explanation, rootPosition)
'{}
case IsNoMatchingImplicits(x) =>
case x: NoMatchingImplicits =>
error("NoMatchingImplicits\n" + x.explanation, rootPosition)
'{}
case IsAmbiguousImplicits(x) =>
case x: AmbiguousImplicits =>
error("AmbiguousImplicits\n" + x.explanation, rootPosition)
'{}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/neg-macros/delegate-match-3/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ inline def f: Any = ${ fImpl }
private def fImpl(given qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty.{_, given}
searchImplicit(('[A]).unseal.tpe) match {
case IsImplicitSearchSuccess(x) =>
case x: ImplicitSearchSuccess =>
'{}
case IsDivergingImplicit(x) => '{}
case x: DivergingImplicit => '{}
error("DivergingImplicit\n" + x.explanation, rootPosition)
'{}
case IsNoMatchingImplicits(x) =>
case x: NoMatchingImplicits =>
error("NoMatchingImplicits\n" + x.explanation, rootPosition)
'{}
case IsAmbiguousImplicits(x) =>
case x: AmbiguousImplicits =>
error("AmbiguousImplicits\n" + x.explanation, rootPosition)
'{}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/tasty-macro-assert-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Asserts {
val tree = cond.unseal

def isOps(tpe: TypeOrBounds): Boolean = tpe match {
case IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts
case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts
case _ => false
}

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/tasty-macro-assert-2/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Asserts {
val tree = cond.unseal

def isOps(tpe: TypeOrBounds): Boolean = tpe match {
case IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts
case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ object Macros {
val output = new TreeTraverser {
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = {
tree match {
case IsDefinition(tree @ DefDef(name, _, _, _, _)) =>
case tree @ DefDef(name, _, _, _, _) =>
buff.append(name)
buff.append("\n")
buff.append(tree.symbol.owner.tree.showExtractors)
buff.append("\n\n")
case IsDefinition(tree @ ValDef(name, _, _)) =>
case tree @ ValDef(name, _, _) =>
buff.append(name)
buff.append("\n")
buff.append(tree.symbol.owner.tree.showExtractors)
Expand Down
6 changes: 3 additions & 3 deletions tests/run-macros/flops-rewrite-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ private class Rewriter(preTransform: List[Transformation[_]] = Nil, postTransfor
import qctx.tasty.{_, given}
class MapChildren extends TreeMap {
override def transformTerm(tree: Term)(given ctx: Context): Term = tree match {
case IsClosure(_) =>
case _: Closure =>
tree
case IsInlined(_) | IsSelect(_) =>
case _: Inlined | _: Select =>
transformChildrenTerm(tree)
case _ =>
tree.tpe.widen match {
case IsMethodType(_) | IsPolyType(_) =>
case _: MethodType | _: PolyType =>
transformChildrenTerm(tree)
case _ =>
tree.seal match {
Expand Down
6 changes: 3 additions & 3 deletions tests/run-macros/flops-rewrite-3/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ private class Rewriter private (preTransform: List[Transformation] = Nil, postTr
import qctx.tasty.{_, given}
class MapChildren extends TreeMap {
override def transformTerm(tree: Term)(given ctx: Context): Term = tree match {
case IsClosure(_) =>
case _: Closure =>
tree
case IsInlined(_) | IsSelect(_) =>
case _: Inlined | _: Select =>
transformChildrenTerm(tree)
case _ =>
tree.tpe.widen match {
case IsMethodType(_) | IsPolyType(_) =>
case _: MethodType | _: PolyType =>
transformChildrenTerm(tree)
case _ =>
tree.seal match {
Expand Down
6 changes: 3 additions & 3 deletions tests/run-macros/flops-rewrite/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ private class Rewriter(preTransform: Expr[Any] => Expr[Any], postTransform: Expr
import qctx.tasty.{_, given}
class MapChildren extends TreeMap {
override def transformTerm(tree: Term)(given ctx: Context): Term = tree match {
case IsClosure(_) =>
case _: Closure =>
tree
case IsInlined(_) | IsSelect(_) =>
case _: Inlined | _: Select =>
transformChildrenTerm(tree)
case _ =>
tree.tpe.widen match {
case IsMethodType(_) | IsPolyType(_) =>
case _: MethodType | _: PolyType =>
transformChildrenTerm(tree)
case _ =>
tree.seal match {
Expand Down
7 changes: 4 additions & 3 deletions tests/run-macros/inferred-repeated-result/test_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ object Macros {
val methods =
tree.tpe.classSymbol.get.classMethods.map { m =>
val name = m.show
val IsDefDef(ddef) = m.tree
val returnType = ddef.returnTpt.tpe.show
s"$name : $returnType"
m.tree match
case ddef: DefDef =>
val returnType = ddef.returnTpt.tpe.show
s"$name : $returnType"
}.sorted

methods.foldLeft('{}) { (res, m) => '{ $res; println(${m}) } }
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/tasty-custom-show/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ object Macros {
// Use custom Show[_] here
val printer = dummyShow
tree match {
case IsDefinition(tree @ DefDef(name, _, _, _, _)) =>
case tree @ DefDef(name, _, _, _, _) =>
buff.append(name)
buff.append("\n")
buff.append(printer.showTree(tree))
buff.append("\n\n")
case IsDefinition(tree @ ValDef(name, _, _)) =>
case tree @ ValDef(name, _, _) =>
buff.append(name)
buff.append("\n")
buff.append(printer.showTree(tree))
Expand Down
13 changes: 7 additions & 6 deletions tests/run-macros/tasty-eval/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ object Macros {
import qctx.tasty.{_, given}

e.unseal.tpe match {
case IsTermRef(pre) if pre.termSymbol.isValDef =>
val IsValDef(t) = pre.termSymbol.tree
t.tpt.tpe match {
case ConstantType(Constant(i: Int)) => Some(i)
case _ => None
}
case pre: TermRef if pre.termSymbol.isValDef =>
pre.termSymbol.tree match
case t: ValDef =>
t.tpt.tpe match {
case ConstantType(Constant(i: Int)) => Some(i)
case _ => None
}
case ConstantType(Constant(i: Int)) => Some(i)
case _ => None
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/tasty-extractors-3/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ object Macros {
val buff = new StringBuilder
val traverser = new TreeTraverser {
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
case IsTypeBoundsTree(tree) =>
case tree: TypeBoundsTree =>
buff.append(tree.tpe.showExtractors)
buff.append("\n\n")
traverseTreeChildren(tree)
case IsTypeTree(tree) =>
case tree: TypeTree =>
buff.append(tree.tpe.showExtractors)
buff.append("\n\n")
traverseTreeChildren(tree)
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/tasty-macro-assert/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Asserts {
val tree = cond.unseal

def isOps(tpe: TypeOrBounds): Boolean = tpe match {
case IsTermRef(tpe) => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts
case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts
case _ => false
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/tasty-seal-method/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Asserts {
x.unseal.underlyingArgument match {
case Apply(fn, args) =>
fn.tpe.widen match {
case IsMethodType(_) =>
case _: MethodType =>
args.size match {
case 0 => Expr.betaReduce(fn.etaExpand.seal.cast[() => Int])()
case 1 => Expr.betaReduce(fn.etaExpand.seal.cast[Int => Int])('{0})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
def interpretCall(inst: AbstractAny, sym: Symbol, args: List[AbstractAny]): Result = {
// TODO
// withLocalValue(`this`, inst) {
val IsDefDef(ddef) = sym.tree
val syms = ddef.paramss.headOption.getOrElse(Nil).map(_.symbol)
withLocalValues(syms, args.map(LocalValue.valFrom(_))) {
eval(ddef.rhs.get)
}
sym.tree match
case ddef: DefDef =>
val syms = ddef.paramss.headOption.getOrElse(Nil).map(_.symbol)
withLocalValues(syms, args.map(LocalValue.valFrom(_))) {
eval(ddef.rhs.get)
}
// }
}

Expand All @@ -42,11 +43,12 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
case _ =>
}
val evaluatedArgs = argss.flatten.map(arg => LocalValue.valFrom(eval(arg)))
val IsDefDef(ddef) = fn.symbol.tree
val syms = ddef.paramss.headOption.getOrElse(Nil).map(_.symbol)
withLocalValues(syms, evaluatedArgs) {
eval(ddef.rhs.get)
}
fn.symbol.tree match
case ddef: DefDef =>
val syms = ddef.paramss.headOption.getOrElse(Nil).map(_.symbol)
withLocalValues(syms, evaluatedArgs) {
eval(ddef.rhs.get)
}
}

def interpretValGet(fn: Term): Result =
Expand Down Expand Up @@ -207,8 +209,8 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {

private object Call {
def unapply(arg: Tree): Option[(Term, List[TypeTree], List[List[Term]])] = arg match {
case IsSelect(fn) => Some((fn, Nil, Nil))
case IsIdent(fn) => Some((fn, Nil, Nil))
case fn: Select => Some((fn, Nil, Nil))
case fn: Ident => Some((fn, Nil, Nil))
case Apply(Call(fn, targs, args1), args2) => Some((fn, targs, args1 :+ args2))
case TypeApply(Call(fn, _, _), targs) => Some((fn, targs, Nil))
case _ => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Interpreter[R <: Reflection & Singleton](reflect0: R) extends TreeInterpre
// Best effort to try to create a proxy
val sym = fn.symbol.owner
if (sym.isClassDef) {
val IsClassDef(tree) = sym.tree
sym.tree match case tree: ClassDef =>
val parentSymbols = tree.parents.tail.map(_.asInstanceOf[TypeTree].symbol).head
import java.lang.reflect._
val handler: InvocationHandler = new InvocationHandler() {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-with-compiler/tasty-comment-consumer/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CommentConsumer extends TastyConsumer {
object Traverser extends TreeTraverser {

override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match {
case IsDefinition(tree) =>
case tree: Definition =>
tree.symbol.comment match {
case Some(com) => println(com.raw)
case None => println()
Expand Down