diff options
Diffstat (limited to 'src/comptime.zig')
| -rw-r--r-- | src/comptime.zig | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/comptime.zig b/src/comptime.zig index b585598..d872b82 100644 --- a/src/comptime.zig +++ b/src/comptime.zig | |||
| @@ -4,6 +4,7 @@ const std = @import("std"); | |||
| 4 | const testing = std.testing; | 4 | const testing = std.testing; |
| 5 | const heap = std.heap; | 5 | const heap = std.heap; |
| 6 | const mem = std.mem; | 6 | const mem = std.mem; |
| 7 | const debug = std.debug; | ||
| 7 | 8 | ||
| 8 | pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id)) type { | 9 | pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id)) type { |
| 9 | var flags: usize = 0; | 10 | var flags: usize = 0; |
| @@ -56,11 +57,17 @@ pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id)) | |||
| 56 | if (param.names.long == null and param.names.short == null) { | 57 | if (param.names.long == null and param.names.short == null) { |
| 57 | try pos.append(arg.value.?); | 58 | try pos.append(arg.value.?); |
| 58 | } else if (param.takes_value) { | 59 | } else if (param.takes_value) { |
| 59 | // We slice before access to avoid false positive access out of bound | 60 | // If we don't have any optional parameters, then this code should |
| 60 | // compile error. | 61 | // never be reached. |
| 61 | res.options[0..][param.id] = arg.value.?; | 62 | debug.assert(res.options.len != 0); |
| 63 | |||
| 64 | // Hack: Utilize Zigs lazy analyzis to avoid a compiler error | ||
| 65 | if (res.options.len != 0) | ||
| 66 | res.options[param.id] = arg.value.?; | ||
| 62 | } else { | 67 | } else { |
| 63 | res.flags[0..][param.id] = true; | 68 | debug.assert(res.flags.len != 0); |
| 69 | if (res.flags.len != 0) | ||
| 70 | res.flags[param.id] = true; | ||
| 64 | } | 71 | } |
| 65 | } | 72 | } |
| 66 | 73 | ||
| @@ -118,13 +125,13 @@ test "clap.comptime.ComptimeClap" { | |||
| 118 | .names = clap.Names{ | 125 | .names = clap.Names{ |
| 119 | .short = 'a', | 126 | .short = 'a', |
| 120 | .long = "aa", | 127 | .long = "aa", |
| 121 | } | 128 | }, |
| 122 | }, | 129 | }, |
| 123 | clap.Param(void){ | 130 | clap.Param(void){ |
| 124 | .names = clap.Names{ | 131 | .names = clap.Names{ |
| 125 | .short = 'b', | 132 | .short = 'b', |
| 126 | .long = "bb", | 133 | .long = "bb", |
| 127 | } | 134 | }, |
| 128 | }, | 135 | }, |
| 129 | clap.Param(void){ | 136 | clap.Param(void){ |
| 130 | .names = clap.Names{ | 137 | .names = clap.Names{ |