Cannot Fallthrough in Type Switch

cannot fallthrough in type switch

Quick Answer

Go does not allow fallthrough in type switch statements. Handle each type case independently or combine cases.

Why This Happens

Unlike regular switch statements, type switches do not support the fallthrough keyword because the variable has a different type in each case block. If you need to handle multiple types the same way, list them in a single case separated by commas.

The Problem

func process(v interface{}) {
    switch v.(type) {
    case int:
        fallthrough // not allowed in type switch
    case int64:
        fmt.Println("integer type")
    }
}

The Fix

func process(v interface{}) {
    switch v.(type) {
    case int, int64:
        fmt.Println("integer type")
    }
}

Step-by-Step Fix

  1. 1

    Identify the fallthrough

    Find the fallthrough keyword inside a type switch.

  2. 2

    Combine cases

    List multiple types in a single case clause separated by commas.

  3. 3

    Extract shared logic

    If cases need different handling but share some logic, extract the shared part into a function.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free