Skip to content

Triple pointer dereference (<< << << d2) only dereferences once #8

@ehartford

Description

@ehartford

Bug

Nested dereference operators << << << d2 where d2: ***int only perform one level of pointer load, outputting a raw address instead of the final int value.

Reproduction

// examples/10/10.1_pointers_simple.jai line 34
a2: int = 3;
b2: *int = *a2;
c2: **int = *b2;
d2: ***int = *c2;
print("%\n", << << << d2);

Expected: 3
Actual: 6100510096 (a raw address)

Root Cause Analysis

In bytecode_gen.zig line ~5904-5950, the shift_left/dot_star dereference handling has several early-return conditions:

  • Line 5919: if (ctx.typed != null and !ctx.typed.?.typeOf(operand).isPointer() and !operand_source_is_pointer) return operand_reg; — may short-circuit for intermediate deref results
  • Line 5920: if (ctx.pointer_addrs.get(operand_reg)) — the pointer_addrs map tracks address-of results; if the inner deref result was entered into this map, it would emit load instead of load_ptr
  • Line 5927-5933: resolved.local_values.get(operand) with non-pointer type check — shouldn't trigger for unary_expr operands

The typeTextForExpr at line 11125-11128 correctly strips one pointer level per deref, so type inference is fine. The issue is in the bytecode emission logic.

Files

  • bootstrap/src/bytecode_gen.zig (~lines 5904-5950)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions