Skip to content

Commit 7bcaa97

Browse files
Merge pull request #6176 from dotty-staging/fix-#6171
Fix #6171: Make sure symbol exists
2 parents 2ad2879 + bd6589a commit 7bcaa97

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-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
@@ -1018,7 +1018,7 @@ 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.owner.isClass && skipLocal(tree.symbol) =>
1021+
case tree: Ident if tree.symbol.exists && !tree.symbol.owner.isClass && skipLocal(tree.symbol) =>
10221022
tree.symbol.defTree match {
10231023
case defTree: ValOrDefDef => transform(defTree.rhs)
10241024
case _ => tree

tests/pos/i6171/Macro_1.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted._
2+
import scala.tasty._
3+
4+
object scalatest {
5+
6+
inline def assert(x: => Any): Unit = ${ assertImpl('x) }
7+
8+
def assertImpl(x: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
9+
import refl._
10+
x.unseal.underlyingArgument
11+
'{ () }
12+
}
13+
}

tests/pos/i6171/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
import scalatest._
3+
4+
def main(args: Array[String]): Unit = {
5+
assert(new Some(5))
6+
}
7+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 util._
11+
import quoted.Toolbox.Default._
12+
13+
def isImplicitMethodType(tp: Type): Boolean =
14+
Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
15+
cond.unseal.underlyingArgument match {
16+
case t @ Term.Apply(Term.Select(lhs, op), rhs :: Nil) =>
17+
let(lhs) { left =>
18+
let(rhs) { right =>
19+
val app = Term.Select.overloaded(left, op, Nil, right :: Nil)
20+
let(app) { result =>
21+
val l = left.seal[Any]
22+
val r = right.seal[Any]
23+
val b = result.seal[Boolean]
24+
val code = '{ scala.Predef.assert($b) }
25+
code.unseal
26+
}
27+
}
28+
}.seal[Unit]
29+
case Term.Apply(f @ Term.Apply(Term.Select(Term.Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
30+
if isImplicitMethodType(f.tpe) =>
31+
let(lhs) { left =>
32+
let(rhs) { right =>
33+
val app = Term.Select.overloaded(Term.Apply(qual, left :: Nil), op, Nil, right :: Nil)
34+
let(Term.Apply(app, implicits)) { result =>
35+
val l = left.seal[Any]
36+
val r = right.seal[Any]
37+
val b = result.seal[Boolean]
38+
val code = '{ scala.Predef.assert($b) }
39+
code.unseal
40+
}
41+
}
42+
}.seal[Unit]
43+
}
44+
}
45+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
import scalatest._
3+
4+
def main(args: Array[String]): Unit = {
5+
assert(new Some(5).get == 5L)
6+
}
7+
}

0 commit comments

Comments
 (0)