diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 64f56047c181..92fbd50a0669 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -1018,9 +1018,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { */ class MapToUnderlying extends TreeMap { override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { - case tree: Ident if tree.symbol.exists && !tree.symbol.owner.isClass && skipLocal(tree.symbol) => + case tree: Ident if tree.symbol.exists && !tree.symbol.owner.isClass && !tree.symbol.isAnonymousFunction && skipLocal(tree.symbol) => tree.symbol.defTree match { - case defTree: ValOrDefDef => transform(defTree.rhs) + case defTree: ValOrDefDef if !defTree.rhs.isEmpty => transform(defTree.rhs) case _ => tree } case Inlined(_, _, arg) => transform(arg) diff --git a/tests/run-with-compiler/i5715/Macro_1.scala b/tests/run-with-compiler/i5715/Macro_1.scala new file mode 100644 index 000000000000..7a3811e5fd8a --- /dev/null +++ b/tests/run-with-compiler/i5715/Macro_1.scala @@ -0,0 +1,20 @@ +import scala.quoted._ +import scala.tasty._ + +object scalatest { + + inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } + + def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { + import refl._ + + cond.unseal.underlyingArgument match { + case app @ Term.Apply(sel @ Term.Select(lhs, op), rhs :: Nil) => + val Term.IsSelect(select) = sel + val cond = Term.Apply(Term.Select.copy(select)(lhs, "exists"), rhs :: Nil).seal[Boolean] + '{ scala.Predef.assert($cond) } + case _ => + '{ scala.Predef.assert($cond) } + } + } +} diff --git a/tests/run-with-compiler/i5715/Test_2.scala b/tests/run-with-compiler/i5715/Test_2.scala new file mode 100644 index 000000000000..19a116cf3f85 --- /dev/null +++ b/tests/run-with-compiler/i5715/Test_2.scala @@ -0,0 +1,8 @@ +object Test { + import scalatest._ + + def main(args: Array[String]): Unit = { + val l = List(3, 4) + assert(l.exists(_ == 3)) + } +}