File tree Expand file tree Collapse file tree 9 files changed +25
-88
lines changed
compiler/src/dotty/tools/dotc/tastyreflect
library/src/scala/tasty/reflect
tests/run-with-compiler-custom-args/tasty-interpreter/interpreter Expand file tree Collapse file tree 9 files changed +25
-88
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {
4040 def Contravariant : Flags = core.Flags .Contravariant
4141 def Scala2X : Flags = core.Flags .Scala2x
4242 def DefaultParameterized : Flags = core.Flags .DefaultParameterized
43- def Stable : Flags = core.Flags .StableRealizable
43+ def StableRealizable : Flags = core.Flags .StableRealizable
4444 def Param : Flags = core.Flags .Param
4545 def ParamAccessor : Flags = core.Flags .ParamAccessor
4646 }
Original file line number Diff line number Diff line change @@ -193,6 +193,11 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
193193 val sym = symbol.moduleClass
194194 if (sym.exists) Some (sym.asClass) else None
195195 }
196+
197+ def companionClass (implicit ctx : Context ): Option [ClassSymbol ] = {
198+ val sym = symbol.companionClass
199+ if (sym.exists) Some (sym.asClass) else None
200+ }
196201 }
197202
198203 object IsBindSymbol extends IsBindSymbolModule {
Original file line number Diff line number Diff line change @@ -93,8 +93,8 @@ trait FlagsOps extends Core {
9393 /** Is this symbol a method with default parameters */
9494 def DefaultParameterized : Flags
9595
96- /** Is this symbol member that is assumed to be stable */
97- def Stable : Flags
96+ /** Is this symbol member that is assumed to be stable and realizable */
97+ def StableRealizable : Flags
9898
9999 /** Is this symbol a parameter */
100100 def Param : Flags
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ trait Printers
126126 if (flags.is(Flags .Contravariant )) flagList += " Flags.Contravariant"
127127 if (flags.is(Flags .Scala2X )) flagList += " Flags.Scala2X"
128128 if (flags.is(Flags .DefaultParameterized )) flagList += " Flags.DefaultParameterized"
129- if (flags.is(Flags .Stable )) flagList += " Flags.Stable "
129+ if (flags.is(Flags .StableRealizable )) flagList += " Flags.StableRealizable "
130130 if (flags.is(Flags .Param )) flagList += " Flags.Param"
131131 if (flags.is(Flags .ParamAccessor )) flagList += " Flags.ParamAccessor"
132132 flagList.result().mkString(" | " )
@@ -501,7 +501,7 @@ trait Printers
501501 if (flags.is(Flags .Contravariant )) flagList += " contravariant"
502502 if (flags.is(Flags .Scala2X )) flagList += " scala2x"
503503 if (flags.is(Flags .DefaultParameterized )) flagList += " defaultParameterized"
504- if (flags.is(Flags .Stable )) flagList += " stable "
504+ if (flags.is(Flags .StableRealizable )) flagList += " stableRealizable "
505505 if (flags.is(Flags .Param )) flagList += " param"
506506 if (flags.is(Flags .ParamAccessor )) flagList += " paramAccessor"
507507 flagList.result().mkString(" /*" , " " , " */" )
Original file line number Diff line number Diff line change @@ -155,6 +155,8 @@ trait SymbolOps extends Core {
155155
156156 /** The class symbol of the companion module class */
157157 def moduleClass (implicit ctx : Context ): Option [ClassSymbol ]
158+
159+ def companionClass (implicit ctx : Context ): Option [ClassSymbol ]
158160 }
159161 implicit def ValSymbolDeco (symbol : ValSymbol ): ValSymbolAPI
160162
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) {
6767 case ValDef (name, tpt, Some (rhs)) =>
6868 def evalRhs = eval(rhs)(accEnv)
6969 val evalRef : LocalValue =
70- if (stat.symbol.flags.isLazy ) LocalValue .lazyValFrom(evalRhs)
71- else if (stat.symbol.flags.isMutable ) LocalValue .varFrom(evalRhs)
70+ if (stat.symbol.flags.is( Flags . Lazy ) ) LocalValue .lazyValFrom(evalRhs)
71+ else if (stat.symbol.flags.is( Flags . Mutable ) ) LocalValue .varFrom(evalRhs)
7272 else LocalValue .valFrom(evalRhs)
7373
7474 accEnv.updated(stat.symbol, evalRef)
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ class Interpreter[R <: Reflection & Singleton](reflect0: R) extends TreeInterpre
7777 // FIXME not necesarly static
7878 jvmReflection.interpretStaticVal(fn.symbol.owner, fn.symbol)
7979 case _ =>
80- if (fn.symbol.flags.isObject )
80+ if (fn.symbol.flags.is( Flags . Object ) )
8181 jvmReflection.loadModule(fn.symbol.asVal.moduleClass.get)
8282 else
8383 jvmReflection.interpretStaticVal(fn.symbol.owner, fn.symbol)
Original file line number Diff line number Diff line change @@ -11,16 +11,16 @@ class JVMReflection[R <: Reflection & Singleton](val reflect: R) {
1111 final val MODULE_INSTANCE_FIELD = " MODULE$"
1212
1313 def loadModule (sym : Symbol ): Object = {
14- if (sym.owner.flags.isPackage) {
15- // is top level object
16- val moduleClass = getClassOf(sym)
17- moduleClass.getField( MODULE_INSTANCE_FIELD ).get( null )
18- }
19- else {
20- // nested object in an object
21- // val clazz = loadClass(sym.fullNameSeparated(FlatName))
22- // clazz.getConstructor().newInstance().asInstanceOf[Object]
23- ???
14+
15+ sym.owner match {
16+ case IsPackageSymbol (_) =>
17+ val moduleClass = getClassOf(sym )
18+ moduleClass.getField( MODULE_INSTANCE_FIELD ).get( null )
19+ case _ =>
20+ // nested object in an object
21+ // val clazz = loadClass(sym.fullNameSeparated(FlatName))
22+ // clazz.getConstructor().newInstance().asInstanceOf[Object]
23+ ???
2424 }
2525 }
2626
You can’t perform that action at this time.
0 commit comments