fun length(s: String?): Int { // after this guard, s is known non-null if (s == null) return 0 return s.length } fun main() { println(length("hello")) println(length(null)) }
the compiler narrows the type