Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperAuguste committed Apr 15, 2024
1 parent 76642fc commit d093a52
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/typing/distinct_integers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
//! with any number representing an index into `B`, but if we were to,
//! for example, access `A` with a number representing an index into `B`,
//! we could access garbage information or cause an out of bounds accesss.
//!
//!
//! A real world example I've run into while working on ZLS is accidentally
//! swapping `TokenIndex`s and `Ast.Node.Index`s, which are both `= u32`.
//!
//!
//! ```zig
//! pub fn accessANodeNotDistinct(node_index: u32) void {
//! // ...
//! }
//!
//!
//! const token_index_not_a_node: u32 = 10;
//! accessANodeNotDistinct(token_index_not_a_node);
//!
//!
//! // kabloom!
//! ```
//!
//!
//! How can we avoid this? Distinct integers!

const std = @import("std");

pub const TokenIndex = enum(u32) {_};
pub const NodeIndex = enum(u32) {_};
pub const TokenIndex = enum(u32) { _ };
pub const NodeIndex = enum(u32) { _ };

pub fn lastToken() TokenIndex {
return @enumFromInt(0);
Expand Down

0 comments on commit d093a52

Please sign in to comment.