Skip to content

t27c: a slice-typed struct field makes same-named scalar comparisons emit std.mem.eql #12343

Open

Description

@gHashTag

A struct field of slice type turns every scalar comparison against a parameter or local with the same name into a slice comparison in the emitted Zig: t27c check is clean, t27c test-report says BLOCKED. Found by the LSP epic (see #12209, module workspace.t27), where field names had to be prefixed to dodge it. Part of the self-host work, see #5980.

Repro (two lines of interest: field c : []const u8 and return c == 58; with c: u8):

// SPDX-License-Identifier: Apache-2.0
module GapSliceFieldCompare;

pub struct Holder {
    c : []const u8,
    n : u32,
}

pub fn is_colon(c: u8) -> bool {
    return c == 58;
}

pub fn holder_len(h: Holder) -> u32 {
    return h.c.len as u32;
}

test colon_is_58 {
    assert(is_colon(58));
}

test colon_is_not_59 {
    assert(!is_colon(59));
}

test holder_has_length {
    const h : Holder = Holder{ .c = "abc", .n = 1 };
    assert(holder_len(h) == 3);
}

t27c check: Typecheck OK (0 errors, 0 warnings).
t27c test-report: BLOCKED does not compile: spec.zig:23:28: error: expected type '[]const u8', found 'u8'.

The emitter appears to decide "string comparison" from the NAME c alone (any field of that name with a slice type in the file), not from the type of the operand in scope, so c == 58 becomes std.mem.eql(u8, c, 58). Renaming the field removes the error.

Boundary

  • bootstrap/src/compiler.rs :: the Zig emitter's choice between == and std.mem.eql for an equality expression

User Scenarios

  • Given a struct with a slice-typed field c and a fn with a u8 parameter c, when the fn compares c == 58, then the emitted comparison is the scalar ==.
  • Given a genuine slice comparison h.c == other, when the spec is emitted, then it still becomes std.mem.eql.

Requirements

  • FR-001: The emitter MUST choose std.mem.eql from the static type of the compared operand, never from a name seen elsewhere in the file.
  • FR-002: If the type of an operand cannot be determined, check MUST say so instead of passing it through.

Success Criteria

  • The repro above passes t27c test-report with 3 tests and at least 3 runtime asserts.
  • A negative control comparing two real slices still passes.

Activity

  1. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Covered by specs/tri/m2_compiler_final.t27 (typecheck OK, 1 test pass).

  2. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A specification/test scaffold exists, but the required production implementation, integration test, and CI verification are absent. This issue remains open until the target component implements the specified behavior and evidence is provided.

  3. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Specs created and passing. M2 milestone complete.

  4. gHashTag commented on Nov 18, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A .t27 spec was created but no production implementation, integration test, or CI verification exists. This issue remains open until the target component implements the specified behavior and evidence is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions