Defining a block in a switch statement results in a compiler error

The block definition creates a new scope which seems to interfere with the compiler’s ability to correctly interpret the switch statement.

Adding scope delimiters for each case label resolves the error. I think this is because the block’s scope is now unambiguously a child of the case scope.

switch (buttonIndex) {
    case 0:
    {
        [self updateUserDataWithCompletion:^{
            [weakSelf finishEditing];
        }];
        break;
    }
    case 1:
    {
        [self updateOtherDataWithCompletion:^{
            [weakSelf finishEditing];
        }];
        break;
    }
    default:
        break;
}

There’s a bug open with LLVM for a similar issue.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)