Skip to content

Opaque types used in struct fields pass check but fail at codegen as unsized types #42

Closed

Description

@ehartford

Current behavior

A program can pass with check, but fail during with run when a struct contains a field of an opaque type.

Minimal repro:

type Handle = opaque

type Wrapper = {
    h: Handle,
}

fn main:
    let w = Wrapper { h: 0 as Handle }
    let _ = w

Commands:

with check /tmp/opaque_field.w
with run /tmp/opaque_field.w

with check output:

ok

with run fails in LLVM verification with errors like:

LLVM verify error: Cannot allocate unsized type
  %0 = alloca %Wrapper, align 8
...
storing unsized types is not allowed
...
GEP into unsized type!
...
error: code generation failed
error: run failed

Expected behavior

An opaque handle type should be usable as a field inside ordinary structs. This is a standard handle-wrapper pattern.

If opaque is intentionally not storable in structs, that should be rejected during semantic analysis with a clear diagnostic. But it should not pass with check and then fail in LLVM verification.

Why this matters

The spec explicitly uses opaque handles for runtime resources and c_import emits forward declarations as type Name = opaque. Users need to be able to wrap those handles inside normal value types without hitting backend verification failures.

Activity

  1. added
    bug
    on Mar 23, 2026
  2. ehartford commented on Mar 23, 2026

    @ehartford
    ContributorAuthor

    Closed by commit 0366e82.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions