Skip to content

Fix #5715: Make sure the val has a RHS #6177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2019
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/run-with-compiler/i5715/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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) }
}
}
}
8 changes: 8 additions & 0 deletions tests/run-with-compiler/i5715/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test {
import scalatest._

def main(args: Array[String]): Unit = {
val l = List(3, 4)
assert(l.exists(_ == 3))
}
}