# translate-c: Ensure assignments are within a block when necessary · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/dce612ac2be5aa8a1aa0ee8dd670d7e875624216)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: dce612ac2be5aa8a1aa0ee8dd670d7e875624216

Requested commit: dce612ac2be5aa8a1aa0ee8dd670d7e875624216

Commit: dce612ac2be5aa8a1aa0ee8dd670d7e875624216

Tree: 5d551dbee5d5cb9f5270f40ea62057961440fc3f

Author: Evan Haas

Committer: Veikka Tuominen

## Message

````
translate-c: Ensure assignments are within a block when necessary

Ensures that if an assignment statement is the sole statement within a
C if statement, for loop, do loop, or do while loop, then when translated
it resides within a block, even though it does not in the original C.

Fixes the following invalid translation:

`if (1) if (1) 2;` -> `if (true) if (true) _ = @as(c_int, 2);`

To this:
```zig
    if (true) if (true) {
        _ = @as(c_int, 2);
    };
```

Fixes #8159

````

## Parents

- [187af14599a083f728f79c4a57ceed30fd01f85d](https://git.cafe/gitcafe/zig/commit/187af14599a083f728f79c4a57ceed30fd01f85d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/dce612ac2be5aa8a1aa0ee8dd670d7e875624216?format=markdown)
