minor fixups

This commit is contained in:
Andrew Kelley 2018-08-27 18:31:28 -04:00
parent e2a9f2ef98
commit 45d9d9f953
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 16 additions and 17 deletions

View File

@ -8488,7 +8488,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
return result;
}
// *T and [*]T can always cast to ?*c_void
// *T and [*]T can always cast to *c_void
if (wanted_type->id == TypeTableEntryIdPointer &&
wanted_type->data.pointer.ptr_len == PtrLenSingle &&
wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&

View File

@ -487,20 +487,20 @@ fn MakeType(comptime T: type) type {
}
test "implicit cast from *[N]T to ?[*]T" {
var x: ?[*]u16 = null;
var y: [4]u16 = [4]u16 {0, 1, 2, 3};
var x: ?[*]u16 = null;
var y: [4]u16 = [4]u16{ 0, 1, 2, 3 };
x = &y;
assert(std.mem.eql(u16, x.?[0..4], y[0..4]));
x.?[0] = 8;
y[3] = 6;
assert(std.mem.eql(u16, x.?[0..4], y[0..4]));
x = &y;
assert(std.mem.eql(u16, x.?[0..4], y[0..4]));
x.?[0] = 8;
y[3] = 6;
assert(std.mem.eql(u16, x.?[0..4], y[0..4]));
}
test "implicit cast from *T to ?*c_void" {
var a: u8 = 1;
incrementVoidPtrValue(&a);
std.debug.assert(a == 2);
var a: u8 = 1;
incrementVoidPtrValue(&a);
std.debug.assert(a == 2);
}
fn incrementVoidPtrValue(value: ?*c_void) void {
@ -508,15 +508,14 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
}
test "implicit cast from [*]T to ?*c_void" {
var a = []u8{3, 2, 1};
incrementVoidPtrArray(a[0..].ptr, 3);
std.debug.assert(std.mem.eql(u8, a, []u8{4, 3, 2}));
var a = []u8{ 3, 2, 1 };
incrementVoidPtrArray(a[0..].ptr, 3);
assert(std.mem.eql(u8, a, []u8{ 4, 3, 2 }));
}
fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
var n: usize = 0;
while(n < len) : (n += 1) {
std.debug.warn("{}", n);
while (n < len) : (n += 1) {
@ptrCast([*]u8, array.?)[n] += 1;
}
}
}