Why does the compiler remove the check?