@@ -203,6 +203,7 @@ object Objects:
203203
204204 /**
205205 * Represents a lambda expression
206+ * @param klass The enclosing class of the anonymous function's creation site
206207 */
207208 case class Fun (code : Tree , thisV : ThisValue , klass : ClassSymbol , env : Env .Data ) extends ValueElement :
208209 def show (using Context ) = " Fun(" + code.show + " , " + thisV.show + " , " + klass.show + " )"
@@ -600,9 +601,10 @@ object Objects:
600601 case _ => a
601602
602603 def filterType (tpe : Type )(using Context ): Value =
604+ // if tpe is SAMType and a is Fun, allow it
603605 val baseClasses = tpe.baseClasses
604606 if baseClasses.isEmpty then a
605- else filterClass(baseClasses.head)
607+ else filterClass(baseClasses.head) // could have called ClassSymbol, but it does not handle OrType and AndType
606608
607609 def filterClass (sym : Symbol )(using Context ): Value =
608610 if ! sym.isClass then a
@@ -613,7 +615,11 @@ object Objects:
613615 case ref : Ref if ref.klass.isSubClass(klass) => ref
614616 case ref : Ref => Bottom
615617 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
618+ case arr : OfArray => if defn.ArrayClass .isSubClass(klass) then arr else Bottom
619+ case fun : Fun => if defn.Function1 .isSubClass(klass) then fun else Bottom
620+ // TODO: could be more precise for OfArray; possibly add class information for Fun
621+ // If ArrayClass.isSubClass(klass) keep the array else discard (see Definitions.scala)
622+ // For function, if any superclass is FunctionClass (or a single abstract method interface?), allow it
617623
618624 extension (value : Ref | Cold .type )
619625 def widenRefOrCold (height : Int )(using Context ) : Ref | Cold .type = value.widen(height).asInstanceOf [ThisValue ]
@@ -859,7 +865,7 @@ object Objects:
859865 report.warning(" [Internal error] unexpected tree in assignment, fun = " + fun.code.show + Trace .show, Trace .position)
860866
861867 case arr : OfArray =>
862- report.warning(" [Internal error] unexpected tree in assignment, array = " + arr.show + Trace .show, Trace .position)
868+ report.warning(" [Internal error] unexpected tree in assignment, array = " + arr.show + " field = " + field + Trace .show, Trace .position)
863869
864870 case Cold =>
865871 report.warning(" Assigning to cold aliases is forbidden. " + Trace .show, Trace .position)
@@ -1566,7 +1572,7 @@ object Objects:
15661572 report.warning(" The argument should be a constant integer value" , arg)
15671573 res.widen(1 )
15681574 case _ =>
1569- res.widen(1 )
1575+ res.widen(1 ) // TODO: changing to widen(2) causes standard library analysis to loop infinitely
15701576
15711577 argInfos += ArgInfo (widened, trace.add(arg.tree), arg.tree)
15721578 }
0 commit comments