Skip to content

A user method colliding with §16.2a c_import sugar is lowered unchecked: MirLower ICE 'callee kind 0', no diagnostic #2403

Closed

Description

@ehartford

On main (installed with v0.15.3.0-g3d03845f9) a user impl T method named like the §16.2a auto-method the translator emits for T_name(T*) is accepted by Sema with no diagnostic, and MIR then lowers the sugar's body, which Sema never checked:

use c_import("tree.h")   // typedef struct xdoc {...} xdoc; static inline xnode *xdoc_root(xdoc *d) { return d->root; }

impl xdoc:
    fn root() -> i32: 7

fn main:
    let d = unsafe { xdoc_parse("x") }
    print(f"{unsafe { (*d).root() }}")
BUG: call of `xdoc_root` has callee kind 0 at expression lowering: node=14322 [src/MirLower.w:17188 MirBuilder.lower_expr_node]

Two defects: (1) Sema records two methods xdoc.root (the sugar's and the user's) and neither errors nor says which wins; (2) the losing body is still lowered (a tool that stayed silent: MIR lowers a body Sema never checked). Expected: either the user's method shadows the sugar (sugar is presentation, §16.2a, and may be omitted) with the sugar decl dropped before lowering, or a diagnostic naming the collision. Found while implementing D122 record-view hosts (the facade's impl xnode collided with the sugar; the D122 branch suppresses the sugar on view types through ci_set_no_methods).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced.

    $ cat tree.h
    typedef struct xnode { int v; } xnode;
    typedef struct xdoc { xnode *root; } xdoc;
    … static inline xdoc *xdoc_parse(const char *s); static inline xnode *xdoc_root(xdoc *d) { return d->root; }
    $ cat main.w
    use c_import("tree.h")
    impl xdoc:
        fn root() -> i32: 7
    fn main:
        let d = unsafe { xdoc_parse(c"x".ptr) }
        print(f"{unsafe { (*d).root() }}")
    $ with run main.w
    BUG: call of `xdoc_root` has callee kind 0 at expression lowering: node=16687 [src/MirLower.w:17456 MirBuilder.lower_expr_node]
    

    pre-release: an internal error from an ordinary method name on a C type; Sema should report the collision.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 2396bc9 (PR #2651, stack #2658; battery green on the stack top 48c1c72). The commit message names the root-cause line and the regression test.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions