File tree 1 file changed +7
-7
lines changed
1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 5
5
//! with any number representing an index into `B`, but if we were to,
6
6
//! for example, access `A` with a number representing an index into `B`,
7
7
//! we could access garbage information or cause an out of bounds accesss.
8
- //!
8
+ //!
9
9
//! A real world example I've run into while working on ZLS is accidentally
10
10
//! swapping `TokenIndex`s and `Ast.Node.Index`s, which are both `= u32`.
11
- //!
11
+ //!
12
12
//! ```zig
13
13
//! pub fn accessANodeNotDistinct(node_index: u32) void {
14
14
//! // ...
15
15
//! }
16
- //!
16
+ //!
17
17
//! const token_index_not_a_node: u32 = 10;
18
18
//! accessANodeNotDistinct(token_index_not_a_node);
19
- //!
19
+ //!
20
20
//! // kabloom!
21
21
//! ```
22
- //!
22
+ //!
23
23
//! How can we avoid this? Distinct integers!
24
24
25
25
const std = @import ("std" );
26
26
27
- pub const TokenIndex = enum (u32 ) {_ };
28
- pub const NodeIndex = enum (u32 ) {_ };
27
+ pub const TokenIndex = enum (u32 ) { _ };
28
+ pub const NodeIndex = enum (u32 ) { _ };
29
29
30
30
pub fn lastToken () TokenIndex {
31
31
return @enumFromInt (0 );
You can’t perform that action at this time.
0 commit comments