forked from ziglang/zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sema: allow slicing *T with comptime known [0..1]
- Loading branch information
Showing
4 changed files
with
127 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/cases/compile_errors/slice_of_single-item_pointer_bounds.zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const value: u8 = 1; | ||
const ptr = &value; | ||
|
||
comptime { | ||
_ = ptr[0..]; | ||
} | ||
|
||
comptime { | ||
_ = ptr[1..2]; | ||
} | ||
|
||
comptime { | ||
_ = ptr[0..2]; | ||
} | ||
|
||
comptime { | ||
_ = ptr[2..2]; | ||
} | ||
|
||
export fn entry1() void { | ||
var start: usize = 0; | ||
_ = ptr[start..2]; | ||
} | ||
|
||
export fn entry2() void { | ||
var end: usize = 0; | ||
_ = ptr[0..end]; | ||
} | ||
|
||
// error | ||
// | ||
// :5:12: error: slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1] | ||
// :9:13: error: slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1] | ||
// :9:13: note: expected '0', found '1' | ||
// :13:16: error: slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1] | ||
// :13:16: note: expected '1', found '2' | ||
// :17:16: error: end index 2 out of bounds for slice of single-item pointer | ||
// :22:13: error: unable to resolve comptime value | ||
// :22:13: note: slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1] | ||
// :27:16: error: unable to resolve comptime value | ||
// :27:16: note: slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1] |
This file was deleted.
Oops, something went wrong.