@@ -203,6 +203,7 @@ object Objects:
203
203
204
204
/**
205
205
* Represents a lambda expression
206
+ * @param klass The enclosing class of the anonymous function's creation site
206
207
*/
207
208
case class Fun (code : Tree , thisV : ThisValue , klass : ClassSymbol , env : Env .Data ) extends ValueElement :
208
209
def show (using Context ) = " Fun(" + code.show + " , " + thisV.show + " , " + klass.show + " )"
@@ -600,9 +601,10 @@ object Objects:
600
601
case _ => a
601
602
602
603
def filterType (tpe : Type )(using Context ): Value =
604
+ // if tpe is SAMType and a is Fun, allow it
603
605
val baseClasses = tpe.baseClasses
604
606
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
606
608
607
609
def filterClass (sym : Symbol )(using Context ): Value =
608
610
if ! sym.isClass then a
@@ -613,7 +615,11 @@ object Objects:
613
615
case ref : Ref if ref.klass.isSubClass(klass) => ref
614
616
case ref : Ref => Bottom
615
617
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
617
623
618
624
extension (value : Ref | Cold .type )
619
625
def widenRefOrCold (height : Int )(using Context ) : Ref | Cold .type = value.widen(height).asInstanceOf [ThisValue ]
@@ -859,7 +865,7 @@ object Objects:
859
865
report.warning(" [Internal error] unexpected tree in assignment, fun = " + fun.code.show + Trace .show, Trace .position)
860
866
861
867
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)
863
869
864
870
case Cold =>
865
871
report.warning(" Assigning to cold aliases is forbidden. " + Trace .show, Trace .position)
@@ -1566,7 +1572,7 @@ object Objects:
1566
1572
report.warning(" The argument should be a constant integer value" , arg)
1567
1573
res.widen(1 )
1568
1574
case _ =>
1569
- res.widen(1 )
1575
+ res.widen(1 ) // TODO: changing to widen(2) causes standard library analysis to loop infinitely
1570
1576
1571
1577
argInfos += ArgInfo (widened, trace.add(arg.tree), arg.tree)
1572
1578
}
0 commit comments