Skip to content

Commit bf02752

Browse files
committed
Fix #5715: Make sure the val has a RHS
1 parent 7bcaa97 commit bf02752

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10201020
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
10211021
case tree: Ident if tree.symbol.exists && !tree.symbol.owner.isClass && skipLocal(tree.symbol) =>
10221022
tree.symbol.defTree match {
1023-
case defTree: ValOrDefDef => transform(defTree.rhs)
1023+
case defTree: ValOrDefDef if !defTree.rhs.isEmpty => transform(defTree.rhs)
10241024
case _ => tree
10251025
}
10261026
case Inlined(_, _, arg) => transform(arg)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object scalatest {
5+
6+
inline def assert(condition: Boolean): Unit = ${ assertImpl('condition, '{""}) }
7+
8+
def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
9+
import refl._
10+
import quoted.Toolbox.Default._
11+
12+
cond.unseal.underlyingArgument match {
13+
case app @ Term.Apply(sel @ Term.Select(lhs, op), rhs :: Nil) =>
14+
val Term.IsSelect(select) = sel
15+
val cond = Term.Apply(Term.Select.copy(select)(lhs, "exists"), rhs :: Nil).seal[Boolean]
16+
'{ scala.Predef.assert($cond) }
17+
case _ =>
18+
'{ scala.Predef.assert($cond) }
19+
}
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
import scalatest._
3+
4+
def main(args: Array[String]): Unit = {
5+
val l = List(3, 4)
6+
assert(l.exists(_ == 3))
7+
}
8+
}

0 commit comments

Comments
 (0)