Skip to content

Commit 8412f78

Browse files
author
EnzeXing
committed
Adding support for filtering Fun
1 parent 113002b commit 8412f78

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,11 @@ object Objects:
601601
case _ => a
602602

603603
def filterType(tpe: Type)(using Context): Value =
604-
// if tpe is SAMType and a is Fun, allow it
605604
val baseClasses = tpe.baseClasses
606605
if baseClasses.isEmpty then a
607-
else filterClass(baseClasses.head) // could have called ClassSymbol, but it does not handle OrType and AndType
606+
else tpe match
607+
case t @ SAMType(_, _) if a.isInstanceOf[Fun] => a // if tpe is SAMType and a is Fun, allow it
608+
case _ => filterClass(baseClasses.head) // could have called ClassSymbol, but it does not handle OrType and AndType
608609

609610
def filterClass(sym: Symbol)(using Context): Value =
610611
if !sym.isClass then a
@@ -616,10 +617,9 @@ object Objects:
616617
case ref: Ref => Bottom
617618
case ValueSet(values) => values.map(v => v.filterClass(klass)).join
618619
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
620+
case fun: Fun =>
621+
val functionSuperCls = klass.baseClasses.filter(defn.isFunctionClass)
622+
if functionSuperCls.nonEmpty then fun else Bottom
623623

624624
extension (value: Ref | Cold.type)
625625
def widenRefOrCold(height : Int)(using Context) : Ref | Cold.type = value.widen(height).asInstanceOf[ThisValue]

0 commit comments

Comments
 (0)