?. is used on a value that can never be null

tx0/kotlin:redundant-safe-callrecommendedwarningmaintainability/dead-codedepth fastsmell

What it finds

"text"?.length or name?.length for a val name: String checks for a null that cannot occur. The result has a nullable type for no reason, which spreads ?. and ?: to the code that uses it. A value counts as never null as for redundant-not-null-assertion.

From the rule's source, redundant_safe_call.rs.

Example from the rule's tests
fun lengths(name: String, other: String?, items: List<String>): Int {    val a = name?.lengthtx0 reports: name can never be null, so ?. checks nothing    val b = other?.length    val c = "text"?.lengthtx0 reports: can never be null    val d = items?.sizetx0 reports: items can never be null    return (a ?: 0) + (b ?: 0) + (c ?: 0) + (d ?: 0)}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:redundant-safe-call" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:redundant-safe-call] reason="..."

tx0 explain tx0/kotlin:redundant-safe-call shows the same in the terminal. Found a false positive? Report it.