Skip to content

Commit d40582d

Browse files
Merge pull request #6843 from dotty-staging/fix-nosymbol-extractor
Fix NoSymbol extractor
2 parents e2130b9 + 1d21f32 commit d40582d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
16701670

16711671
type NoSymbol = core.Symbols.NoSymbol.type
16721672

1673-
def matchNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol ne core.Symbols.NoSymbol
1673+
def matchNoSymbol(symbol: Symbol)(implicit ctx: Context): Boolean = symbol eq core.Symbols.NoSymbol
16741674

16751675
//
16761676
// FLAGS

tests/run-macros/no-symbol/1.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.quoted._
2+
import scala.deriving._
3+
4+
case class Foo(i: Int)
5+
case class Box[A](x: A)
6+
7+
object Macro {
8+
inline def foo[T](implicit inline t: Type[T]): String =
9+
${ fooImpl }
10+
11+
def fooImpl[T](implicit t: Type[T], q: QuoteContext): Expr[String] = {
12+
import q.tasty._
13+
t.unseal.symbol match {
14+
case IsClassDefSymbol(self) => '{ "symbol" }
15+
case NoSymbol() => '{ "no symbol" }
16+
case _ => '{ "match error" }
17+
}
18+
}
19+
}

tests/run-macros/no-symbol/2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
assert(Macro.foo[Foo] == "symbol")
4+
assert(Macro.foo[Box] == "no symbol")
5+
}
6+
}

0 commit comments

Comments
 (0)