@@ -629,17 +629,10 @@ trait Applications extends Compatibility {
629
629
630
630
def applyKind = ApplyKind .Regular
631
631
632
- /** Is `tp1` a function type that can be converted by a SAM comversion to `tp2`,
633
- * and that is not at the same time a supertype of `tp2`?
632
+ /** Is `arg` with widened type `argType` a function literal that can be converted by a SAM
633
+ * conversion to `pt`? Overridden in ApplicableToTrees.
634
634
*/
635
- private def isSamCompatible (tp1 : Type , tp2 : Type )(using Context ): Boolean =
636
- defn.isFunctionType(tp1)
637
- && {
638
- tp2.match
639
- case SAMType (sam) => tp1 <:< sam.toFunctionType(isJava = tp2.classSymbol.is(JavaDefined ))
640
- case _ => false
641
- }
642
- && ! (tp2 relaxed_<:< tp1)
635
+ def isSamCompatible (arg : Arg , argType : Type , pt : Type )(using Context ): Boolean = false
643
636
644
637
protected def argOK (arg : TypedArg , formal : Type ): Boolean = argType(arg, formal) match
645
638
case ref : TermRef if ref.denot.isOverloaded =>
@@ -652,18 +645,15 @@ trait Applications extends Compatibility {
652
645
&& formal.match
653
646
case SAMType (sam) => argtpe <:< sam.toFunctionType(isJava = formal.classSymbol.is(JavaDefined ))
654
647
case _ => false
655
- if argMatch == ArgMatch .SubType then
656
- (argtpe relaxed_<:< formal.widenExpr)
657
- || isSamCompatible(argtpe.widen, formal)
658
- else
659
- isCompatible(argtpe, formal)
660
- || isSamCompatible(argtpe.widen, formal)
661
- || argMatch == ArgMatch .CompatibleCAP
662
- && {
663
- val argtpe1 = argtpe.widen
664
- val captured = captureWildcards(argtpe1)
665
- (captured ne argtpe1) && isCompatible(captured, formal.widenExpr)
666
- }
648
+ ( if argMatch == ArgMatch .SubType then argtpe relaxed_<:< formal.widenExpr
649
+ else isCompatible(argtpe, formal) )
650
+ || isSamCompatible(arg, argtpe.widen, formal)
651
+ || argMatch == ArgMatch .CompatibleCAP
652
+ && {
653
+ val argtpe1 = argtpe.widen
654
+ val captured = captureWildcards(argtpe1)
655
+ (captured ne argtpe1) && isCompatible(captured, formal.widenExpr)
656
+ }
667
657
668
658
/** The type of the given argument */
669
659
protected def argType (arg : Arg , formal : Type ): Type
@@ -692,6 +682,14 @@ trait Applications extends Compatibility {
692
682
def isVarArg (arg : Tree ): Boolean = tpd.isWildcardStarArg(arg)
693
683
def typeOfArg (arg : Tree ): Type = arg.tpe
694
684
def harmonizeArgs (args : List [Tree ]): List [Tree ] = harmonize(args)
685
+
686
+ override def isSamCompatible (arg : Tree , argType : Type , pt : Type )(using Context ): Boolean =
687
+ arg match
688
+ case closure(_) =>
689
+ pt match
690
+ case SAMType (sam) => argType <:< sam.toFunctionType(isJava = pt.classSymbol.is(JavaDefined ))
691
+ case _ => false
692
+ case _ => false
695
693
}
696
694
697
695
/** Subclass of Application for applicability tests with value argument types. */
0 commit comments