Skip to content

Commit 913ad7e

Browse files
committed
fix GADT adaption when typing if
fix type assigning for if
1 parent c93a237 commit 913ad7e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
11421142
cpy.If(tree)(cond1, thenp1, elsep1).withType(defn.UnitType)
11431143
else
11441144
val thenp1 :: elsep1 :: Nil = harmonic(harmonize, pt) {
1145-
val thenp0 = typed(tree.thenp, branchPt)(using cond1.nullableContextIf(true))
1146-
val elsep0 = typed(tree.elsep, branchPt)(using cond1.nullableContextIf(false))
1145+
val thenp0 = typedUnadapted(tree.thenp, branchPt)(using cond1.nullableContextIf(true))
1146+
val elsep0 = typedUnadapted(tree.elsep, branchPt)(using cond1.nullableContextIf(false))
11471147
thenp0 :: elsep0 :: Nil
11481148
}
1149-
assignType(cpy.If(tree)(cond1, thenp1, elsep1), thenp1, elsep1)
1149+
1150+
val locked = ctx.typerState.ownedVars
1151+
1152+
val orTpe = thenp1.tpe | elsep1.tpe
1153+
val thenp2 = adapt(thenp1, orTpe, locked)
1154+
val elsep2 = adapt(elsep1, orTpe, locked)
1155+
1156+
assignType(cpy.If(tree)(cond1, thenp2, elsep2), thenp1, elsep1)
11501157

11511158
def thenPathInfo = cond1.notNullInfoIf(true).seq(result.thenp.notNullInfo)
11521159
def elsePathInfo = cond1.notNullInfoIf(false).seq(result.elsep.notNullInfo)

0 commit comments

Comments
 (0)