mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
Sema: in-memory coercion of differently named int types
which have the same number of bits and the same signedness.
This commit is contained in:
parent
9213aa789b
commit
62f54aa39c
11
src/Sema.zig
11
src/Sema.zig
@ -18458,6 +18458,17 @@ fn coerceInMemoryAllowed(
|
||||
if (dest_ty.eql(src_ty, target))
|
||||
return .ok;
|
||||
|
||||
// Differently-named integers with the same number of bits.
|
||||
if (dest_ty.zigTypeTag() == .Int and src_ty.zigTypeTag() == .Int) {
|
||||
const dest_info = dest_ty.intInfo(target);
|
||||
const src_info = src_ty.intInfo(target);
|
||||
if (dest_info.signedness == src_info.signedness and
|
||||
dest_info.bits == src_info.bits)
|
||||
{
|
||||
return .ok;
|
||||
}
|
||||
}
|
||||
|
||||
// Pointers / Pointer-like Optionals
|
||||
var dest_buf: Type.Payload.ElemType = undefined;
|
||||
var src_buf: Type.Payload.ElemType = undefined;
|
||||
|
@ -973,7 +973,8 @@ test "variable initialization uses result locations properly with regards to the
|
||||
}
|
||||
|
||||
test "cast between C pointer with different but compatible types" {
|
||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
fn foo(arg: [*]c_ushort) u16 {
|
||||
@ -985,6 +986,7 @@ test "cast between C pointer with different but compatible types" {
|
||||
}
|
||||
};
|
||||
try S.doTheTest();
|
||||
comptime try S.doTheTest();
|
||||
}
|
||||
|
||||
test "peer type resolve string lit with sentinel-terminated mutable slice" {
|
||||
|
Loading…
Reference in New Issue
Block a user