A Toast is made and never shown

tx0/kotlin:toast-not-showndefaultwarningframeworks/androiddepth fastbug, android

What it finds

Toast.makeText(context, "Saved", Toast.LENGTH_SHORT) only creates the toast; nothing appears until show() is called on it. Reported is a makeText call whose result is dropped as a statement without show() in its chain.

From the rule's source, toast_not_shown.rs.

Example from the rule's tests
fun saved(context: Context) {    Toast.makeText(context, "Saved", Toast.LENGTH_SHORT)tx0 reports: the toast is made but never shown    Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show()    val toast = Toast.makeText(context, "Later", Toast.LENGTH_LONG)    toast.show()}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:toast-not-shown" = "off"

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:toast-not-shown] reason="..."

tx0 explain tx0/kotlin:toast-not-shown shows the same in the terminal. Found a false positive? Report it.