Skip to content

missing comptime undefined propagation for equality operator with pointer, optional, error union, and integers #17798

@Jarred-Sumner

Description

@Jarred-Sumner

The following strictly always is undefined behavior that Zig chooses to compile successfully:

Checking if a value is not equal to undefined:

pub fn deinit(this: *@This()) void {
   if (this.context != undefined) {
    this.allocator.destroy(this.context);
  }
}

Checking if a value is equal to undefined:

pub fn deinit(this: *@This()) void {
   if (this.context == undefined) {
    this.allocator.destroy(this.context);
  }
}

Why isn't this a compiler error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions