@@ -599,6 +599,22 @@ object Objects:
599
599
600
600
case _ => a
601
601
602
+ def filterType (tpe : Type )(using Context ): Value =
603
+ val baseClasses = tpe.baseClasses
604
+ if baseClasses.isEmpty then a
605
+ else filterClass(baseClasses.head)
606
+
607
+ def filterClass (sym : Symbol )(using Context ): Value =
608
+ if ! sym.isClass then a
609
+ else
610
+ val klass = sym.asClass
611
+ a match
612
+ case Cold => Cold
613
+ case ref : Ref if ref.klass.isSubClass(klass) => ref
614
+ case ref : Ref => Bottom
615
+ case ValueSet (values) => values.map(v => v.filterClass(klass)).join
616
+ case _ => a // TODO: could be more precise for OfArray; possibly add class information for Fun
617
+
602
618
extension (value : Ref | Cold .type )
603
619
def widenRefOrCold (height : Int )(using Context ) : Ref | Cold .type = value.widen(height).asInstanceOf [ThisValue ]
604
620
@@ -617,7 +633,7 @@ object Objects:
617
633
* @param needResolve Whether the target of the call needs resolution?
618
634
*/
619
635
def call (value : Value , meth : Symbol , args : List [ArgInfo ], receiver : Type , superType : Type , needResolve : Boolean = true ): Contextual [Value ] = log(" call " + meth.show + " , this = " + value.show + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
620
- value match
636
+ value.filterClass(meth.owner) match
621
637
case Cold =>
622
638
report.warning(" Using cold alias. " + Trace .show, Trace .position)
623
639
Bottom
@@ -733,7 +749,6 @@ object Objects:
733
749
* @param args Arguments of the constructor call (all parameter blocks flatten to a list).
734
750
*/
735
751
def callConstructor (value : Value , ctor : Symbol , args : List [ArgInfo ]): Contextual [Value ] = log(" call " + ctor.show + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
736
-
737
752
value match
738
753
case ref : Ref =>
739
754
if ctor.hasSource then
@@ -768,7 +783,7 @@ object Objects:
768
783
* @param needResolve Whether the target of the selection needs resolution?
769
784
*/
770
785
def select (value : Value , field : Symbol , receiver : Type , needResolve : Boolean = true ): Contextual [Value ] = log(" select " + field.show + " , this = " + value.show, printer, (_ : Value ).show) {
771
- value match
786
+ value.filterClass(field.owner) match
772
787
case Cold =>
773
788
report.warning(" Using cold alias" , Trace .position)
774
789
Bottom
@@ -839,12 +854,12 @@ object Objects:
839
854
* @param rhsTyp The type of the right-hand side.
840
855
*/
841
856
def assign (lhs : Value , field : Symbol , rhs : Value , rhsTyp : Type ): Contextual [Value ] = log(" Assign" + field.show + " of " + lhs.show + " , rhs = " + rhs.show, printer, (_ : Value ).show) {
842
- lhs match
857
+ lhs.filterClass(field.owner) match
843
858
case fun : Fun =>
844
859
report.warning(" [Internal error] unexpected tree in assignment, fun = " + fun.code.show + Trace .show, Trace .position)
845
860
846
861
case arr : OfArray =>
847
- report.warning(" [Internal error] unexpected tree in assignment, array = " + arr.show + Trace .show, Trace .position)
862
+ report.warning(" [Internal error] unexpected tree in assignment, array = " + arr.show + s " , owner = ${field.owner} \n " + Trace .show, Trace .position)
848
863
849
864
case Cold =>
850
865
report.warning(" Assigning to cold aliases is forbidden. " + Trace .show, Trace .position)
@@ -876,8 +891,7 @@ object Objects:
876
891
* @param args The arguments passsed to the constructor.
877
892
*/
878
893
def instantiate (outer : Value , klass : ClassSymbol , ctor : Symbol , args : List [ArgInfo ]): Contextual [Value ] = log(" instantiating " + klass.show + " , outer = " + outer + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
879
- outer match
880
-
894
+ outer.filterClass(klass.owner) match
881
895
case _ : Fun | _ : OfArray =>
882
896
report.warning(" [Internal error] unexpected outer in instantiating a class, outer = " + outer.show + " , class = " + klass.show + " , " + Trace .show, Trace .position)
883
897
Bottom
@@ -1091,6 +1105,9 @@ object Objects:
1091
1105
instantiate(outer, cls, ctor, args)
1092
1106
}
1093
1107
1108
+ case TypeCast (elem, tpe) =>
1109
+ eval(elem, thisV, klass).filterType(tpe)
1110
+
1094
1111
case Apply (ref, arg :: Nil ) if ref.symbol == defn.InitRegionMethod =>
1095
1112
val regions2 = Regions .extend(expr.sourcePos)
1096
1113
if Regions .exists(expr.sourcePos) then
0 commit comments