File tree Expand file tree Collapse file tree 6 files changed +45
-0
lines changed
compiler/src/dotty/tools/dotc/tastyreflect Expand file tree Collapse file tree 6 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -1732,6 +1732,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
1732
1732
case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm
1733
1733
}.toList
1734
1734
1735
+ def Symbol_typeMembers (self : Symbol )(using ctx : Context ): List [Symbol ] =
1736
+ self.unforcedDecls.filter(_.isType)
1737
+
1738
+ def Symbol_typeMember (self : Symbol )(name : String )(using ctx : Context ): Symbol =
1739
+ self.unforcedDecls.find(sym => sym.name == name.toTypeName)
1740
+
1735
1741
def Symbol_classMethods (self : Symbol )(using ctx : Context ): List [Symbol ] =
1736
1742
self.typeRef.decls.iterator.collect {
1737
1743
case sym if isMethod(sym) => sym.asTerm
Original file line number Diff line number Diff line change @@ -2219,6 +2219,14 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2219
2219
def classMethods (using ctx : Context ): List [Symbol ] =
2220
2220
internal.Symbol_classMethods (sym)
2221
2221
2222
+ /** Type member directly declared in the class */
2223
+ def typeMembers (using ctx : Context ): List [Symbol ] =
2224
+ internal.Symbol_typeMembers (sym)
2225
+
2226
+ /** Type member with the given name directly declared in the class */
2227
+ def typeMember (name : String )(using ctx : Context ): Symbol =
2228
+ internal.Symbol_typeMember (sym)(name)
2229
+
2222
2230
/** Get named non-private methods declared or inherited */
2223
2231
def method (name : String )(using ctx : Context ): List [Symbol ] =
2224
2232
internal.Symbol_method (sym)(name)
Original file line number Diff line number Diff line change @@ -1308,6 +1308,12 @@ trait CompilerInterface {
1308
1308
/** Get all non-private methods declared or inherited */
1309
1309
def Symbol_methods (self : Symbol )(using ctx : Context ): List [Symbol ]
1310
1310
1311
+ /** Type member directly declared in the class */
1312
+ def Symbol_typeMembers (self : Symbol )(using ctx : Context ): List [Symbol ]
1313
+
1314
+ /** Type member with the given name directly declared in the class */
1315
+ def Symbol_typeMember (self : Symbol )(name : String )(using ctx : Context ): Symbol
1316
+
1311
1317
/** The symbols of each type parameter list and value parameter list of this
1312
1318
* method, or Nil if this isn't a method.
1313
1319
*/
Original file line number Diff line number Diff line change
1
+ List((A,+))
2
+ List((B,-))
3
+ List((C, ))
Original file line number Diff line number Diff line change
1
+ import scala .quoted ._
2
+
3
+ inline def test [T [_]]: Unit = $ { testExpr[T ] }
4
+
5
+ def testExpr [T [_]: Type ](using QuoteContext ): Expr [Unit ] = {
6
+ import qctx .tasty ._
7
+ def variance (f : Flags ) =
8
+ if f.is(Flags .Covariant ) then " +"
9
+ else if f.is(Flags .Contravariant ) then " -"
10
+ else " "
11
+ val t = ' [T ].unseal.tpe.typeSymbol.typeMembers.map(x => (x.name, variance(x.flags)))
12
+ ' { println($ {Expr (t.toString)}) }
13
+ }
Original file line number Diff line number Diff line change
1
+ trait X [+ A ]
2
+ trait Y [- B ]
3
+ trait Z [C ]
4
+
5
+ @ main def Test = {
6
+ test[X ]
7
+ test[Y ]
8
+ test[Z ]
9
+ }
You can’t perform that action at this time.
0 commit comments