Skip to content

Add Symbol.isSuperAccessor to reflection API #13388

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
merged 1 commit into from
Apr 12, 2024
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
1 change: 1 addition & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def isAnonymousFunction: Boolean = self.denot.isAnonymousFunction
def isAbstractType: Boolean = self.denot.isAbstractType
def isClassConstructor: Boolean = self.denot.isClassConstructor
def isSuperAccessor = self.name.is(dotc.core.NameKinds.SuperAccessorName)
def isType: Boolean = self.isType
def isTerm: Boolean = self.isTerm
def isPackageDef: Boolean = self.is(dotc.core.Flags.Package)
Expand Down
4 changes: 4 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3998,6 +3998,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
/** Is this the constructor of a class? */
def isClassConstructor: Boolean

/** Is this the super accessor? */
@experimental // TODO when stable, remove `dotty.tools.scaladoc.tasty.ClassLikeSupport.isSuperBridgeMethod` and use this method
def isSuperAccessor: Boolean

/** Is this the definition of a type? */
def isType: Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object SyntheticsSupport:
import reflect._
s.flags.is(Flags.Synthetic) || s.flags.is(Flags.FieldAccessor) || s.isDefaultHelperMethod

// TODO remove and use `SymbolMethods.isSuperAccessor`
def isSuperBridgeMethod: Boolean = s.name.contains("$super$")

def isDefaultHelperMethod: Boolean = ".*\\$default\\$\\d+$".r.matches(s.name)
Expand Down
1 change: 1 addition & 0 deletions tests/run-tasty-inspector/isSuperAccessor.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
method SyncIterator$$super$next
39 changes: 39 additions & 0 deletions tests/run-tasty-inspector/isSuperAccessor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import scala.quoted.*
import scala.tasty.inspector.*

@main def Test = {
// Artefact of the current test infrastructure
// TODO improve infrastructure to avoid needing this code on each test
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(_.contains("runWithCompiler")).get
val allTastyFiles = dotty.tools.io.Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList
val tastyFiles = allTastyFiles.filter(_.contains("SyncIterator"))

TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector)
}

class MyInspector extends Inspector:

override def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
import quotes.reflect.*
class Traverser extends TreeTraverser:
override def traverseTree(tree: Tree)(owner: Symbol) =
tree match
case tree: DefDef if tree.symbol.isSuperAccessor =>
println(tree.symbol)
case _ =>
super.traverseTree(tree)(owner)
end Traverser

val traverser = new Traverser
tastys.foreach { tasty =>
traverser.traverseTree(tasty.ast)(tasty.ast.symbol)
}


trait IntIterator {
def next: Int
def drop(n: Int): Unit
}
trait SyncIterator extends IntIterator {
abstract override def next: Int = super.next
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ val experimentalDefinitionInLibrary = Set(
"scala.annotation.init$.region",

//// New APIs: Quotes
// Can be stabilized in 3.4.0 (unsure) or later
// Can be stabilized in 3.5.0 or later
"scala.quoted.Quotes.reflectModule.SymbolMethods.isSuperAccessor",
// Can be stabilized in 3.5.0 (unsure) or later
"scala.quoted.Quotes.reflectModule.CompilationInfoModule.XmacroSettings",
// Cant be stabilized yet.
// Need newClass variant that can add constructor parameters.
Expand Down