mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 05:20:34 +00:00
parent
a3d04b9228
commit
a05150e92d
@ -9243,6 +9243,7 @@ bool type_is_numeric(ZigType *ty) {
|
||||
case ZigTypeIdComptimeInt:
|
||||
case ZigTypeIdInt:
|
||||
case ZigTypeIdFloat:
|
||||
case ZigTypeIdUndefined:
|
||||
return true;
|
||||
|
||||
case ZigTypeIdVector:
|
||||
@ -9255,7 +9256,6 @@ bool type_is_numeric(ZigType *ty) {
|
||||
case ZigTypeIdPointer:
|
||||
case ZigTypeIdArray:
|
||||
case ZigTypeIdStruct:
|
||||
case ZigTypeIdUndefined:
|
||||
case ZigTypeIdNull:
|
||||
case ZigTypeIdOptional:
|
||||
case ZigTypeIdErrorUnion:
|
||||
|
||||
@ -14647,7 +14647,9 @@ never_mind_just_calculate_it_normally:
|
||||
}
|
||||
|
||||
|
||||
if (op1_val->special == ConstValSpecialUndef || op2_val->special == ConstValSpecialUndef) {
|
||||
if (op1_val->special == ConstValSpecialUndef || op2_val->special == ConstValSpecialUndef ||
|
||||
op1_val->type->id == ZigTypeIdUndefined || op2_val->type->id == ZigTypeIdUndefined)
|
||||
{
|
||||
out_val->special = ConstValSpecialUndef;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -2,6 +2,14 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add("comparing against undefined produces undefined value",
|
||||
\\export fn entry() void {
|
||||
\\ if (2 == undefined) {}
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:11: error: use of undefined value here causes undefined behavior",
|
||||
});
|
||||
|
||||
cases.add("comptime ptrcast of zero-sized type",
|
||||
\\fn foo() void {
|
||||
\\ const node: struct {} = undefined;
|
||||
|
||||
@ -671,3 +671,10 @@ test "vector comparison" {
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "compare undefined literal with comptime_int" {
|
||||
var x = undefined == 1;
|
||||
// x is now undefined with type bool
|
||||
x = true;
|
||||
expect(x);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user