Skip to content

Commit 24b914e

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

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
10181018
*/
10191019
class MapToUnderlying extends TreeMap {
10201020
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
1021-
case tree: Ident if tree.symbol.exists && !tree.symbol.owner.isClass && skipLocal(tree.symbol) =>
1021+
case tree: Ident if tree.symbol.exists && !tree.symbol.owner.isClass && !tree.symbol.isAnonymousFunction && 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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
11+
cond.unseal.underlyingArgument match {
12+
case app @ Term.Apply(sel @ Term.Select(lhs, op), rhs :: Nil) =>
13+
val Term.IsSelect(select) = sel
14+
val cond = Term.Apply(Term.Select.copy(select)(lhs, "exists"), rhs :: Nil).seal[Boolean]
15+
'{ scala.Predef.assert($cond) }
16+
case _ =>
17+
'{ scala.Predef.assert($cond) }
18+
}
19+
}
20+
}
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)