# Flow typing for null checks: why not by default?

**URL:** <https://contributors.scala-lang.org/t/flow-typing-for-null-checks-why-not-by-default/7517>\
**Category:** Scala Improvement Process\
**Created:** [July 30, 2026, 4:40pm UTC](https://contributors.scala-lang.org/t/flow-typing-for-null-checks-why-not-by-default/7517 "2026-07-30T16:40:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mberndt](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@mberndt](https://contributors.scala-lang.org/u/mberndt)\
**Post date:** [July 30, 2026, 4:40pm UTC](https://contributors.scala-lang.org/t/flow-typing-for-null-checks-why-not-by-default/7517/1 "2026-07-30T16:40:20Z")

</div>

Under `-Yexplicit-nulls`, Scala currently employs a form of flow typing to enable code like this

```scala
def orZero(x: Int | Null): Int =
  if x != null then x else 0

```

In explicit nulls mode, the compiler determines that it’s OK to use `x`, which is of type `Int | Null`, in a position where `Int` is required, because the appropriate null check has been performed. But when `-Yexplicit-nulls` is not given, this fails to compile:

```auto
-- [E007] Type Mismatch Error: -------------------------------------------------
2 | if x != null then x else 0
  | ^
  | Found: (x : Int | Null)
  | Required: Int
  |

```

Why wouldn’t we always enable this?
