Merge pull request #10034 from Snektron/stage2-slice

stage2: slice and optional improvements
This commit is contained in:
Andrew Kelley
2021-10-25 19:41:19 -04:00
committed by GitHub
7 changed files with 127 additions and 77 deletions

View File

@@ -2347,11 +2347,13 @@ pub const Type = extern union {
}
}
/// Asserts that the type is an optional
/// Asserts that the type is an optional or a pointer that can be null.
pub fn isPtrLikeOptional(self: Type) bool {
switch (self.tag()) {
.optional_single_const_pointer,
.optional_single_mut_pointer,
.c_const_pointer,
.c_mut_pointer,
=> return true,
.optional => {
@@ -2367,6 +2369,8 @@ pub const Type = extern union {
.Many, .One => return !info.@"allowzero",
}
},
.pointer => return self.castTag(.pointer).?.data.size == .C,
else => unreachable,
}
}