Skip to content

Commit 794ef5a

Browse files
Add Symbol.isSuperAccessor to reflection API (#13388)
2 parents 62e0641 + 4971581 commit 794ef5a

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26892689
def isAnonymousFunction: Boolean = self.denot.isAnonymousFunction
26902690
def isAbstractType: Boolean = self.denot.isAbstractType
26912691
def isClassConstructor: Boolean = self.denot.isClassConstructor
2692+
def isSuperAccessor = self.name.is(dotc.core.NameKinds.SuperAccessorName)
26922693
def isType: Boolean = self.isType
26932694
def isTerm: Boolean = self.isTerm
26942695
def isPackageDef: Boolean = self.is(dotc.core.Flags.Package)

library/src/scala/quoted/Quotes.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,6 +4031,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
40314031
/** Is this the constructor of a class? */
40324032
def isClassConstructor: Boolean
40334033

4034+
/** Is this the super accessor? */
4035+
@experimental // TODO when stable, remove `dotty.tools.scaladoc.tasty.ClassLikeSupport.isSuperBridgeMethod` and use this method
4036+
def isSuperAccessor: Boolean
4037+
40344038
/** Is this the definition of a type? */
40354039
def isType: Boolean
40364040

scaladoc/src/dotty/tools/scaladoc/tasty/SyntheticSupport.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object SyntheticsSupport:
1010
import reflect._
1111
s.flags.is(Flags.Synthetic) || s.flags.is(Flags.FieldAccessor) || s.isDefaultHelperMethod
1212

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

1516
def isDefaultHelperMethod: Boolean = ".*\\$default\\$\\d+$".r.matches(s.name)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
method SyncIterator$$super$next
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import scala.quoted.*
2+
import scala.tasty.inspector.*
3+
4+
@main def Test = {
5+
// Artefact of the current test infrastructure
6+
// TODO improve infrastructure to avoid needing this code on each test
7+
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(_.contains("runWithCompiler")).get
8+
val allTastyFiles = dotty.tools.io.Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList
9+
val tastyFiles = allTastyFiles.filter(_.contains("SyncIterator"))
10+
11+
TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector)
12+
}
13+
14+
class MyInspector extends Inspector:
15+
16+
override def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
17+
import quotes.reflect.*
18+
class Traverser extends TreeTraverser:
19+
override def traverseTree(tree: Tree)(owner: Symbol) =
20+
tree match
21+
case tree: DefDef if tree.symbol.isSuperAccessor =>
22+
println(tree.symbol)
23+
case _ =>
24+
super.traverseTree(tree)(owner)
25+
end Traverser
26+
27+
val traverser = new Traverser
28+
tastys.foreach { tasty =>
29+
traverser.traverseTree(tasty.ast)(tasty.ast.symbol)
30+
}
31+
32+
33+
trait IntIterator {
34+
def next: Int
35+
def drop(n: Int): Unit
36+
}
37+
trait SyncIterator extends IntIterator {
38+
abstract override def next: Int = super.next
39+
}

tests/run-tasty-inspector/stdlibExperimentalDefinitions.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ val experimentalDefinitionInLibrary = Set(
5151
"scala.annotation.init$.region",
5252

5353
//// New APIs: Quotes
54-
// Can be stabilized in 3.4.0 (unsure) or later
54+
// Can be stabilized in 3.5.0 or later
55+
"scala.quoted.Quotes.reflectModule.SymbolMethods.isSuperAccessor",
56+
// Can be stabilized in 3.5.0 (unsure) or later
5557
"scala.quoted.Quotes.reflectModule.CompilationInfoModule.XmacroSettings",
5658
// Cant be stabilized yet.
5759
// Need newClass variant that can add constructor parameters.

0 commit comments

Comments
 (0)