@@ -1099,16 +1099,20 @@ class Typer extends Namer
1099
1099
pt match {
1100
1100
case SAMType (sam)
1101
1101
if ! defn.isFunctionType(pt) && mt <:< sam =>
1102
+ // SAMs of the form C[?] where C is a class cannot be conversion targets.
1103
+ // The resulting class `class $anon extends C[?] {...}` would be illegal,
1104
+ // since type arguments to `C`'s super constructor cannot be constructed.
1105
+ def isWildcardClassSAM =
1106
+ ! pt.classSymbol.is(Trait ) && pt.argInfos.exists(_.isInstanceOf [TypeBounds ])
1102
1107
val targetTpe =
1103
- if (! isFullyDefined(pt, ForceDegree .all))
1104
- if (pt.isRef(defn.PartialFunctionClass ))
1105
- // Replace the underspecified expected type by one based on the closure method type
1106
- defn.PartialFunctionOf (mt.firstParamTypes.head, mt.resultType)
1107
- else {
1108
- ctx.error(ex " result type of lambda is an underspecified SAM type $pt" , tree.sourcePos)
1109
- pt
1110
- }
1111
- else pt
1108
+ if isFullyDefined(pt, ForceDegree .all) && ! isWildcardClassSAM then
1109
+ pt
1110
+ else if pt.isRef(defn.PartialFunctionClass ) then
1111
+ // Replace the underspecified expected type by one based on the closure method type
1112
+ defn.PartialFunctionOf (mt.firstParamTypes.head, mt.resultType)
1113
+ else
1114
+ ctx.error(ex " result type of lambda is an underspecified SAM type $pt" , tree.sourcePos)
1115
+ pt
1112
1116
if (pt.classSymbol.isOneOf(FinalOrSealed )) {
1113
1117
val offendingFlag = pt.classSymbol.flags & FinalOrSealed
1114
1118
ctx.error(ex " lambda cannot implement $offendingFlag ${pt.classSymbol}" , tree.sourcePos)
0 commit comments