Skip to content

Struct literal defaults resolve in the literal's module, not the type's: ActionFrame {} needs use game for a default's V2 #2400

Closed

Description

@ehartford

What happened

A struct literal that relies on field defaults fails to compile in a module that does not import the types those defaults mention, even though the defaults are written in the defining module.

In WIPE, src/controls.w declares:

use game   // V2

pub type ActionFrame {
    id: u64 = 0,
    motion: V2 = V2 {}, aim: V2 = V2 {},
    held: u32 = 0, pressed: u32 = 0,
} with Copy

src/steam_uat.w imports controls but not game, and writes var frame = ActionFrame {}. The compiler reports:

error: unknown type 'V2' in struct literal
error: unknown type 'V2' in struct literal

Adding use game to steam_uat.w makes it compile, although steam_uat.w never names V2.

Expected

A field default is part of the type's definition, so it should resolve in the scope of the module that defines the type (controls.w, where V2 is in scope), not in the scope of each literal that omits the field. A caller should not have to know which types a default expression mentions.

Where

  • With: nightly-20261003-local-1-074a38b8fd81 on macOS (the compiler WIPE builds with on 2026-10-13).
  • WIPE: withlang-dev/wipe, commit after "Steam Input proper" (src/controls.w, src/steam_uat.w).

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    ContributorAuthor

    Fixed on main (b050a01, PR #2587, stack #2588): one commit with the fixture test/behavior/behav_2400_field_default_in_declaring_module.w, which failed before the fix and passes after; battery GREEN on the stack top 077d684 (669 s, pinned seed nightly-20261023-local-1).

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions