From 268b43ce7b38fb36447f7438f6af0d886175c573 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Jul 2021 15:20:37 +0200 Subject: [PATCH] Handle isDefinedInCurrentRun on no symbol Fixes #13095 --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 2 +- tests/pos-macros/i13095/Macro_1.scala | 9 +++++++++ tests/pos-macros/i13095/Test_2.scala | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i13095/Macro_1.scala create mode 100644 tests/pos-macros/i13095/Test_2.scala diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 9e6669fe9256..34a0cd99c3f1 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2455,7 +2455,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler } def isDefinedInCurrentRun: Boolean = - self.topLevelClass.asClass.isDefinedInCurrentRun + self.exists && self.topLevelClass.asClass.isDefinedInCurrentRun def isLocalDummy: Boolean = self.denot.isLocalDummy def isRefinementClass: Boolean = self.denot.isRefinementClass def isAliasType: Boolean = self.denot.isAliasType diff --git a/tests/pos-macros/i13095/Macro_1.scala b/tests/pos-macros/i13095/Macro_1.scala new file mode 100644 index 000000000000..776d2a18533a --- /dev/null +++ b/tests/pos-macros/i13095/Macro_1.scala @@ -0,0 +1,9 @@ + +import scala.quoted.* + +inline def testMacro = ${ test } + +def test(using Quotes): Expr[Unit] = + import quotes.reflect.* + assert(!Symbol.noSymbol.isDefinedInCurrentRun) + '{} diff --git a/tests/pos-macros/i13095/Test_2.scala b/tests/pos-macros/i13095/Test_2.scala new file mode 100644 index 000000000000..b301473885ac --- /dev/null +++ b/tests/pos-macros/i13095/Test_2.scala @@ -0,0 +1 @@ +def unitTest = testMacro