Skip to content
Playground(another site)

bynk.types.if_branch_mismatch

Error The branches of an if have different types.

Both branches of an if can be its value, so they must have one type: their common supertype, where a refined type and its base agree at the base. With a String in one branch and an Int in the other, the caller has no single type to rely on. Make the branches agree, converting where needed. A match whose arms disagree is bynk.types.match_arm_mismatch.

Example

fn grade(score: Int) -> String {
if score >= 50 { "pass" } else { 0 } // ✗ a `String` branch and an `Int` branch
}
fn grade(score: Int) -> String {
if score >= 50 { "pass" } else { "fail" } // ✓
}

In the Book

See also

  • The grammar rule it governs: if_expr.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.if_branch_mismatch shows the same from the installed toolchain, without a network.