Skip to content

CCodegen.global_decl_tid: an extern var whose type does not resolve is silently emitted as i32 #1429

Closed

Description

@ehartford

Found while fixing the emit-C reds of #1377 (#1362). Code reading, not yet a repro.

src/CCodegen.w, global_decl_tid: when an extern var's declared type does not resolve through sema.resolve_type_expr_frozen, the global is emitted as i32:

if dk == NodeKind.NK_EXTERN_VAR:
    let type_node = self.ast.get_data1(decl)
    let tid = ...resolve...(type_node)
    if tid != 0:
        return tid
    return self.sema.ty_i32 as i32

That is a silent fallback (AGENTS.md "No Silent Fallbacks"): an extern var whose type the C backend cannot resolve is declared int in the emitted C instead of failing loudly. Until #1377, frozen resolution in CCodegen ran from whatever module sema.current_module_path held. The root module could not see a type, so the i32 branch was reachable for any global whose type the root cannot name. #1377 resolves a declaration's type in its declaring module, which removes that route. The fallback itself is still there.

Expected: self.fail(...) naming the global and its type spelling, like the sizeof path does since #1377.

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