@@ -912,24 +912,6 @@ class Typer extends Namer
912
912
pt, localSyms(stats1))
913
913
}
914
914
915
- def typedUnadaptedWithBlock (tree : untpd.Tree , pt : Type , locked : TypeVars )(using Context ): Tree = {
916
- tree match {
917
- case block : untpd.Block =>
918
- val (stats1, exprCtx) = withoutMode(Mode .Pattern ) {
919
- typedBlockStats(block.stats)(using ctx.fresh.setNewScope)
920
- }
921
- val expr1 = typedUnadaptedWithBlock(block.expr, pt.dropIfProto, locked)(using exprCtx)
922
- val expr1Tpe = expr1.tpe
923
- ensureNoLocalRefs(
924
- cpy.Block (block)(stats1, expr1)
925
- .withType(expr1Tpe)
926
- .withNotNullInfo(stats1.foldRight(expr1.notNullInfo)(_.notNullInfo.seq(_))),
927
- expr1Tpe, localSyms(stats1))
928
- case _ =>
929
- typedUnadapted(tree, pt, locked)
930
- }
931
- }
932
-
933
915
def escapingRefs (block : Tree , localSyms : => List [Symbol ])(using Context ): List [NamedType ] = {
934
916
lazy val locals = localSyms.toSet
935
917
block.tpe.namedPartsWith(tp => locals.contains(tp.symbol) && ! tp.isErroneous)
@@ -3452,13 +3434,23 @@ class Typer extends Namer
3452
3434
return tpd.Block (tree1 :: Nil , Literal (Constant (())))
3453
3435
}
3454
3436
3437
+ val adaptWithUnsafeNullConver =
3438
+ ctx.explicitNulls && (
3439
+ config.Feature .enabled(nme.unsafeNulls) ||
3440
+ ctx.mode.is(Mode .UnsafeNullConversion ))
3441
+
3455
3442
// convert function literal to SAM closure
3456
3443
tree match {
3457
3444
case closure(Nil , id @ Ident (nme.ANON_FUN ), _)
3458
3445
if defn.isFunctionType(wtp) && ! defn.isFunctionType(pt) =>
3459
- pt match {
3446
+ val pt1 =
3447
+ if adaptWithUnsafeNullConver then
3448
+ pt.stripNull
3449
+ else pt
3450
+ pt1 match {
3460
3451
case SAMType (sam)
3461
- if wtp <:< sam.toFunctionType() =>
3452
+ if wtp <:< sam.toFunctionType() ||
3453
+ (adaptWithUnsafeNullConver && wtp.isUnsafeConvertable(sam.toFunctionType())) =>
3462
3454
// was ... && isFullyDefined(pt, ForceDegree.flipBottom)
3463
3455
// but this prevents case blocks from implementing polymorphic partial functions,
3464
3456
// since we do not know the result parameter a priori. Have to wait until the
@@ -3544,7 +3536,17 @@ class Typer extends Namer
3544
3536
tree
3545
3537
else recover(failure.reason)
3546
3538
3547
- def process (using Context ): Tree = {
3539
+ val javaCompatibleCall = ctx.explicitNullsJavaCompatible && (tree match {
3540
+ case Apply (_, _) => tree.symbol.is(JavaDefined )
3541
+ case _ => false
3542
+ })
3543
+
3544
+ val searchCtx =
3545
+ if ctx.explicitNulls && (javaCompatibleCall || config.Feature .enabled(nme.unsafeNulls)) then
3546
+ ctx.addMode(Mode .UnsafeNullConversion )
3547
+ else ctx
3548
+
3549
+ inContext(searchCtx) {
3548
3550
if ctx.mode.is(Mode .ImplicitsEnabled ) && tree.typeOpt.isValueType then
3549
3551
if pt.isRef(defn.AnyValClass ) || pt.isRef(defn.ObjectClass ) then
3550
3552
report.error(em " the result of an implicit conversion must be more specific than $pt" , tree.srcPos)
@@ -3558,17 +3560,6 @@ class Typer extends Namer
3558
3560
}
3559
3561
else tryUnsafeNullConver(recover(NoMatchingImplicits ))
3560
3562
}
3561
-
3562
- val javaCompatibleCall = ctx.explicitNullsJavaCompatible && (tree match {
3563
- case Apply (_, _) => tree.symbol.is(JavaDefined )
3564
- case _ => false
3565
- })
3566
- val searchCtx =
3567
- if ctx.explicitNulls && (javaCompatibleCall || config.Feature .enabled(nme.unsafeNulls)) then
3568
- ctx.addMode(Mode .UnsafeNullConversion )
3569
- else ctx
3570
-
3571
- process(using searchCtx)
3572
3563
}
3573
3564
3574
3565
def adaptType (tp : Type ): Tree = {
0 commit comments