Skip to content

Load pointer-indexed struct elements as values during code generation #501

Closed

Description

@LunaStev

A semantically valid copy of a struct from a pointer-indexed array fails during object emission on master 611cc87:

struct Item { key: i32; ordinal: i32; value: i64; }
fun load(items: ptr<Item>, index: i64) -> i64 {
    var item: Item = items[index];
    return item.value;
}
fun main() -> i32 {
    var items: array<Item, 1> = [Item { key: 1, ordinal: 0, value: 9000000000 }];
    if (load(&items[0], 0) != 9000000000) { return 1; }
    return 0;
}

wavec check accepts it, but wavec build fails with E9001 / Type mismatch: expected StructType ... got PointerType in llvm/src/statement/variable.rs.

The indexed rvalue path in llvm/src/expression/rvalue/index.rs returns a storage address for structs, while variable initialization expects a struct value. Preserve the distinct address-of/lvalue path and load struct rvalues with the correct type.

Acceptance: struct-element copies, assignments, pointer accesses and nested field projections execute correctly. Include a stable-sort workload with duplicate keys, wide values, guard fields, a large returned aggregate and checks that copies do not alias. Verify LLVM targets individually and keep existing aggregate/variant tests passing. A local fix is in validation; no commit or push yet.

Activity

  1. added
    bug
    help wanted
    cross-platform
    on Sep 7, 2026
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

    bugcross-platformhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions