Skip to content

Commit cdb1b44

Browse files
committed
Add a warning about operator precedence in schema
1 parent 7be7b24 commit cdb1b44

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pages/spicedb/concepts/schema.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ definition document {
177177

178178
### Operations
179179

180+
<Callout type="warning">
181+
**Important: Union Precedence**
182+
183+
For historical reasons, union (`+`) takes precedence over intersection (`&`) and exclusion (`-`), which can lead to unexpected results.
184+
For example, `a + b & c` is evaluated as `(a + b) & c`, not `a + (b & c)`.
185+
186+
We intend to add a flag to fix this precedence issue in the future.
187+
188+
It is highly recommended to either:
189+
190+
- Break complex expressions into intermediate permissions:
191+
192+
```zed
193+
permission writers_and_admins = writer & admin
194+
permission view = reader + writers_and_admins
195+
```
196+
197+
- Use explicit parentheses to clarify precedence:
198+
199+
```zed
200+
permission view = reader + (writer & admin)
201+
```
202+
203+
</Callout>
204+
180205
Permissions support four kinds of operations: **union**, **intersection**, **exclusion** and **arrow**.
181206

182207
#### `+` (Union)

0 commit comments

Comments
 (0)