@@ -1345,27 +1345,26 @@ class Typer extends Namer
1345
1345
if (tree.tpt.isEmpty)
1346
1346
meth1.tpe.widen match {
1347
1347
case mt : MethodType =>
1348
- val pt1 = pt.stripNull
1349
- pt1 match {
1350
- case SAMType (sam)
1348
+ pt.stripNull match {
1349
+ case pt @ SAMType (sam)
1351
1350
if ! defn.isFunctionType(pt) && mt <:< sam =>
1352
1351
// SAMs of the form C[?] where C is a class cannot be conversion targets.
1353
1352
// The resulting class `class $anon extends C[?] {...}` would be illegal,
1354
1353
// since type arguments to `C`'s super constructor cannot be constructed.
1355
1354
def isWildcardClassSAM =
1356
- ! pt1 .classSymbol.is(Trait ) && pt1 .argInfos.exists(_.isInstanceOf [TypeBounds ])
1355
+ ! pt .classSymbol.is(Trait ) && pt .argInfos.exists(_.isInstanceOf [TypeBounds ])
1357
1356
val targetTpe =
1358
- if isFullyDefined(pt1 , ForceDegree .all) && ! isWildcardClassSAM then
1359
- pt1
1360
- else if pt1 .isRef(defn.PartialFunctionClass ) then
1357
+ if isFullyDefined(pt , ForceDegree .all) && ! isWildcardClassSAM then
1358
+ pt
1359
+ else if pt .isRef(defn.PartialFunctionClass ) then
1361
1360
// Replace the underspecified expected type by one based on the closure method type
1362
1361
defn.PartialFunctionOf (mt.firstParamTypes.head, mt.resultType)
1363
1362
else
1364
- report.error(ex " result type of lambda is an underspecified SAM type $pt1 " , tree.srcPos)
1365
- pt1
1366
- if (pt1 .classSymbol.isOneOf(FinalOrSealed )) {
1367
- val offendingFlag = pt1 .classSymbol.flags & FinalOrSealed
1368
- report.error(ex " lambda cannot implement $offendingFlag ${pt1 .classSymbol}" , tree.srcPos)
1363
+ report.error(ex " result type of lambda is an underspecified SAM type $pt " , tree.srcPos)
1364
+ pt
1365
+ if (pt .classSymbol.isOneOf(FinalOrSealed )) {
1366
+ val offendingFlag = pt .classSymbol.flags & FinalOrSealed
1367
+ report.error(ex " lambda cannot implement $offendingFlag ${pt .classSymbol}" , tree.srcPos)
1369
1368
}
1370
1369
TypeTree (targetTpe)
1371
1370
case _ =>
@@ -3645,15 +3644,6 @@ class Typer extends Namer
3645
3644
if target <:< pt then
3646
3645
return readapt(tree.cast(target))
3647
3646
3648
- def tryUnsafeNullConver (fail : => Tree ): Tree =
3649
- // In explcit-nulls, if first subtyping fails, the unsafe-nulls subtyping
3650
- // (where `Null` is subtype of all reference types) is used here to
3651
- // recheck the types.
3652
- if pt.isValueType && (wtp <:< pt) then
3653
- // If unsafe-nulls subtyping successes, we can cast the tree to `pt` directly
3654
- tree.cast(pt)
3655
- else fail
3656
-
3657
3647
def recover (failure : SearchFailureType ) =
3658
3648
if canDefineFurther(wtp) then readapt(tree)
3659
3649
else err.typeMismatch(tree, pt, failure)
@@ -3682,18 +3672,16 @@ class Typer extends Namer
3682
3672
checkImplicitConversionUseOK(found)
3683
3673
withoutMode(Mode .ImplicitsEnabled )(readapt(found))
3684
3674
case failure : SearchFailure =>
3685
- tryUnsafeNullConver {
3686
- if (pt.isInstanceOf [ProtoType ] && ! failure.isAmbiguous) then
3687
- // don't report the failure but return the tree unchanged. This
3688
- // will cause a failure at the next level out, which usually gives
3689
- // a better error message. To compensate, store the encountered failure
3690
- // as an attachment, so that it can be reported later as an addendum.
3691
- rememberSearchFailure(tree, failure)
3692
- tree
3693
- else recover(failure.reason)
3694
- }
3675
+ if (pt.isInstanceOf [ProtoType ] && ! failure.isAmbiguous) then
3676
+ // don't report the failure but return the tree unchanged. This
3677
+ // will cause a failure at the next level out, which usually gives
3678
+ // a better error message. To compensate, store the encountered failure
3679
+ // as an attachment, so that it can be reported later as an addendum.
3680
+ rememberSearchFailure(tree, failure)
3681
+ tree
3682
+ else recover(failure.reason)
3695
3683
case _ =>
3696
- tryUnsafeNullConver( recover(NoMatchingImplicits ) )
3684
+ recover(NoMatchingImplicits )
3697
3685
end adaptToSubType
3698
3686
3699
3687
def adaptType (tp : Type ): Tree = {
0 commit comments