diff --git a/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala b/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala index 99a4da63128a..8aed9e5b9771 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/internal/SemanticdbInputStream.scala @@ -143,8 +143,7 @@ class SemanticdbInputStream private (buffer: Array[Byte], input: InputStream) { throw new IllegalStateException( s"refillBuffer() called when $n bytes were already available in buffer") } - if (totalBytesRetired + bufferPos + n > currentLimit) false - else if (input != null) { + if totalBytesRetired + bufferPos + n <= currentLimit && input != null then val pos: Int = bufferPos if (pos > 0) { if (bufferSize > pos) { @@ -166,7 +165,6 @@ class SemanticdbInputStream private (buffer: Array[Byte], input: InputStream) { recomputeBufferSizeAfterLimit() return ((bufferSize >= n) || tryRefillBuffer(n)) } - } false } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 6c1767f6ef83..191d324d99d0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1128,15 +1128,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer if tree.isInline then checkInInlineContext("inline if", tree.srcPos) val cond1 = typed(tree.cond, defn.BooleanType) + def isIncomplete(tree: untpd.If): Boolean = tree.elsep match + case EmptyTree => true + case elsep: untpd.If => isIncomplete(elsep) + case _ => false + + val branchPt = if isIncomplete(tree) then defn.UnitType else pt.dropIfProto + val result = if tree.elsep.isEmpty then - val thenp1 = typed(tree.thenp, defn.UnitType)(using cond1.nullableContextIf(true)) + val thenp1 = typed(tree.thenp, branchPt)(using cond1.nullableContextIf(true)) val elsep1 = tpd.unitLiteral.withSpan(tree.span.endPos) cpy.If(tree)(cond1, thenp1, elsep1).withType(defn.UnitType) else val thenp1 :: elsep1 :: Nil = harmonic(harmonize, pt) { - val thenp0 = typed(tree.thenp, pt.dropIfProto)(using cond1.nullableContextIf(true)) - val elsep0 = typed(tree.elsep, pt.dropIfProto)(using cond1.nullableContextIf(false)) + val thenp0 = typed(tree.thenp, branchPt)(using cond1.nullableContextIf(true)) + val elsep0 = typed(tree.elsep, branchPt)(using cond1.nullableContextIf(false)) thenp0 :: elsep0 :: Nil } assignType(cpy.If(tree)(cond1, thenp1, elsep1), thenp1, elsep1) diff --git a/tests/pos/i14914.scala b/tests/pos/i14914.scala new file mode 100644 index 000000000000..3208a5cf8a02 --- /dev/null +++ b/tests/pos/i14914.scala @@ -0,0 +1,8 @@ + +def Test(b: Boolean) = + val a = + if b then + 1 + else if !b then + 2 + val _: Unit = a