Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion sourcecode/src-3/sourcecode/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ trait ArgsMacros {
}

object Util{
def isSynthetic(using Quotes)(s: quotes.reflect.Symbol) = isSyntheticName(getName(s))
def isSynthetic(using Quotes)(s: quotes.reflect.Symbol) =
isSyntheticAlt(s)

def isSyntheticAlt(using Quotes)(s: quotes.reflect.Symbol) = {
import quotes.reflect._
s.flags.is(Flags.Synthetic) || s.isClassConstructor || s.isLocalDummy || isScala2Macro(s)
}
def isScala2Macro(using Quotes)(s: quotes.reflect.Symbol) = {
import quotes.reflect._
(s.flags.is(Flags.Macro) && s.owner.flags.is(Flags.Scala2x)) ||
(s.flags.is(Flags.Macro) && !s.flags.is(Flags.Inline))
}
def isSyntheticName(name: String) = {
name == "<init>" || (name.startsWith("<local ") && name.endsWith(">")) || name == "$anonfun" || name == "macro"
}
Expand Down
13 changes: 13 additions & 0 deletions sourcecode/test/src/sourcecode/SpecialName.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sourcecode

object SpecialName {

def macroValRun() = {
def keyword(implicit name: sourcecode.Name): String = name.value

val `macro` = keyword

assert(`macro` == "macro")
}

}
1 change: 1 addition & 0 deletions sourcecode/test/src/sourcecode/Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object Tests{
EnumFull.run()
NoSynthetic.run()
Synthetic.run()
SpecialName.macroValRun()
ManualImplicit()
TextTests()
ArgsTests()
Expand Down