Skip to content

Two modules that each c_import: the root's c_import expansion binds the other module's private C scalar aliases (c_uint, c_ulonglong) #1372

Closed

Description

@ehartford

Found while sweeping for #1362. Pre-existing on the #1364 branch's stage2 (a9b7fc3) and on the installed compiler.

A program whose root module and an imported module each use c_import(...) does not compile: the root's c_import expansion references the C scalar aliases (c_uint, c_ulonglong, ...) and they resolve to the imported module's private copies.

// cu.w
use c_import("<stdio.h>")
pub fn greet() -> str: "hi"

// m.w
use cu
use c_import("<stdlib.h>")
fn main:
    print(greet())
    print(f"{abs(-3)}")

with run m.w:

error: symbol 'c_ulonglong' is private to module 'cu.w'
 --> <c_import <stdlib.h>>:10:46
10 | type __darwin_arm_exception_state64 { __far: c_ulonglong = 0, __esr: c_uint = 0, __exception: c_uint = 0 }

Expected: each module's c_import surface is its own (the root sees its own c_uint); both programs compile (m.w without use cu runs and prints 3).

With the #1362 gate fix the diagnostic changes to 'c_uint' requires an explicit import (§18.1); add: use std.re.defs.c_uint: once cu.w's copy is invisible, the only other candidate is the pcre2 corpus's alias, which used to leak through the prelude. That fix-it is wrong for this program; the defect is the missing root-module alias. Legacy repro in-tree: tests/cimport_scope/test_own_ci.w (fails before and after).

Spec: §16 (c_import), §18.1 (current-module declarations outrank imports), §18.3 (module privacy).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions