Skip to content

Add scala.Symbol constants to Tasty reflect #4874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,12 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s
}
}

object Symbol extends SymbolExtractor {
def unapply(x: Constant): Option[scala.Symbol] = x match {
case x: Constants.Constant if x.tag == Constants.ScalaSymbolTag => Some(x.scalaSymbolValue)
case _ => None
}
}
}

// ===== Signature ================================================
Expand Down
7 changes: 0 additions & 7 deletions compiler/test/dotc/pos-decompilation.blacklist
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# Constant(Symbol)
desugar.scala
sip23-symbols.scala
t389.scala
t4812.scala
t4579.scala

# assertion failed: asTerm called on not-a-Term val <none>
cls.scala
escapes2.scala
Expand Down
8 changes: 0 additions & 8 deletions compiler/test/dotc/run-decompilation.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ t3651.scala
protectedacc.scala
t7436.scala

# Constant(Symbol)
fors.scala
t6634.scala
t6632.scala
t4601.scala
t6633.scala
arrays.scala

# scala.MatchError: SeqLiteral in pattern
i3248.scala
t6541.scala
Expand Down
7 changes: 7 additions & 0 deletions library/src/scala/tasty/Tasty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,13 @@ abstract class Tasty { tasty =>
abstract class ClassTagExtractor {
def unapply(x: Constant): Option[Type]
}

/** Extractor for scala.Symbol literals */
val Symbol: SymbolExtractor
/** Extractor for scala.Symbol literals */
abstract class SymbolExtractor {
def unapply(x: Constant): Option[scala.Symbol]
}
}

// ===== Signature ================================================
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/util/ShowExtractors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case Constant.Double(value) => this += "Constant.Double(" += value += ")"
case Constant.String(value) => this += "Constant.String(\"" += value += "\")"
case Constant.ClassTag(value) => this += "Constant.ClassTag(" += value += ")"
case Constant.Symbol(value) => this += "Constant.Symbol('" += value.name += ")"
}

def visitType(x: TypeOrBounds): Buffer = x match {
Expand Down
2 changes: 2 additions & 0 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case Constant.ClassTag(v) =>
this += "classOf"
inSquare(printType(v))
case Constant.Symbol(v) =>
this += "'" += v.name
}

def printTypeOrBoundsTree(tpt: TypeOrBoundsTree): Buffer = tpt match {
Expand Down