Skip to content

Imported type aliases in struct fields pass 'with check' but fail codegen with 'unresolved type' #31

Closed

Description

@ehartford

Current behavior

A type alias imported from another module works in function signatures, but if you use that imported alias as a struct field type, with check says ok and with run fails during codegen:

error: unresolved type for field 'device' in struct 'Pair'
error: code generation failed
error: run failed

Minimal repro

mkdir -p /tmp/wbug/lib/demo

cat > /tmp/wbug/lib/demo/core.w <<'EOF'
pub type Device = i64
EOF

cat > /tmp/wbug/lib/demo/program.w <<'EOF'
use demo.core

type Pair = {
    device: Device,
}

pub fn ok(device: Device) -> bool:
    let pair = Pair { device }
    pair.device == device
EOF

cat > /tmp/wbug/main.w <<'EOF'
use demo.program

fn main:
    assert(ok(7))
EOF

cd /tmp/wbug && with check main.w   # says ok
cd /tmp/wbug && with run main.w     # fails in codegen

Control case

The same pattern works if the alias is defined in the same file instead of imported:

type Device = i64

type Pair = {
    device: Device,
}

fn main:
    let pair = Pair { device: 7 }
    assert(pair.device == 7)

That checks and runs successfully.

Expected behavior

Imported aliases should lower exactly like local aliases. The repro above should compile and run.

If there is some unsupported case here, the compiler should reject it during with check with a precise diagnostic instead of reaching codegen and reporting unresolved type.

Why this matters

This blocks any library that exposes opaque handles as public aliases in one module and then uses those aliases in runtime structs in another module. Crux uses this pattern for Device, Program, Stream, and similar handle types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugerror-messages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions