Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Ondřej Lhoták <[email protected]>
  • Loading branch information
noti0na1 and olhotak authored Oct 14, 2024
1 parent 0a319be commit ada9da3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ object Nullables:
val hiTree = if(hiTpe eq hi.typeOpt) hi else TypeTree(hiTpe)
TypeBoundsTree(lo, hiTree, alias)

/** A set of val or var references that are known to be not null,
* plus a set of variable references that are once assigned to null.
/** A set of val or var references that are known to be not null
* after the tree finishes executing normally (non-exceptionally),
* plus a set of variable references that are ever assigned to null,
* and may therefore be null if execution of the tree is interrupted
* by an exception.
*/
case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef]):
def isEmpty = this eq NotNullInfo.empty
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val cases2 = cases2x.asInstanceOf[List[CaseDef]]

// It is possible to have non-exhaustive cases, and some exceptions are thrown and not caught.
// Therefore, the code in the finallizer and after the try block can only rely on the retracted
// Therefore, the code in the finalizer and after the try block can only rely on the retracted
// info from the cases' body.
if cases2.nonEmpty then
nnInfo = nnInfo.seq(cases2.map(_.notNullInfo.retractedInfo).reduce(_.alt(_)))
Expand Down
2 changes: 1 addition & 1 deletion tests/explicit-nulls/neg/i21380c.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test4: Int =
case _ => x = ""
x.length // error
// Although the catch block here is exhaustive, it is possible to have non-exhaustive cases,
// and some exceptions are thrown and not caught. Therefore, the code in the finallizer and
// and some exceptions are thrown and not caught. Therefore, the code in the finalizer and
// after the try block can only rely on the retracted info from the cases' body.

def test5: Int =
Expand Down

0 comments on commit ada9da3

Please sign in to comment.