google / google/emboss

Struct-level `[requires]` aren't enforced on field writes

Open
#126 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
92
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Suppose I have the following Emboss definition:

```
struct Foo:
[requires: bar == 0]
0 [+1] UInt bar
```

If I were to write a non-zero value into `bar`, `emboss_prelude.h:185 EMBOSS_CHECK(result);` wouldn't execute and the write would succeed. It wouldn't be until I called `bool Ok()` that I would find out that something was written incorrectly. At that point, I just get a boolean `true` or `false` and not a directed, clear result of what went wrong.

This isn't the case if I place the `[requires]` block on the field itself:

```
struct Foo:
0 [+1] UInt bar
[requires: this == 0]
```

This second Emboss definition would catch the non-zero write via `emboss_prelude.h:185 EMBOSS_CHECK(result);`. Regardless of where the `[requires]` block is placed, we should catch incorrect writes when they happen.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.