Skip to content

Commit 040360b

Browse files
committed
Fix Java Compatible for Block arg
1 parent efc3a62 commit 040360b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,14 @@ object ProtoTypes {
370370
if wideFormal eq formal then ctx
371371
else ctx.withNotNullInfos(ctx.notNullInfos.retractMutables)
372372
val locked = ctx.typerState.ownedVars
373-
val nullConver = ctx.mode.is(Mode.UnsafeNullConversion)
374-
if nullConver then
375-
val targ = typer.typedUnadapted(arg, WildcardType, locked)(using argCtx.retractMode(Mode.UnsafeNullConversion))
376-
typer.adapt(targ, wideFormal, locked)
373+
val targ = if ctx.mode.is(Mode.UnsafeNullConversion) then
374+
typer.typedUnadaptedWithBlock(arg, wideFormal, locked)
375+
(using argCtx.retractMode(Mode.UnsafeNullConversion))
377376
else
378-
val targ = cacheTypedArg(arg,
377+
cacheTypedArg(arg,
379378
typer.typedUnadapted(_, wideFormal, locked)(using argCtx),
380379
force = true)
381-
typer.adapt(targ, wideFormal, locked)
380+
typer.adapt(targ, wideFormal, locked)
382381
}
383382

384383
/** The type of the argument `arg`, or `NoType` if `arg` has not been typed before

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,24 @@ class Typer extends Namer
912912
pt, localSyms(stats1))
913913
}
914914

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+
915933
def escapingRefs(block: Tree, localSyms: => List[Symbol])(using Context): List[NamedType] = {
916934
lazy val locals = localSyms.toSet
917935
block.tpe.namedPartsWith(tp => locals.contains(tp.symbol) && !tp.isErroneous)

0 commit comments

Comments
 (0)