// A protocol method declared with a real pointer return (`-> *u8`,
// NOT `-> Self`) returns the raw pointer to the caller without the
// dispatch path auto-dereferencing it. Without this, a method whose
// pointee is a single byte gets `sizeof(target)` bytes loaded past
// it and segfaults.

#import "modules/std.sx";

Proto :: protocol {
  get :: () -> *u8;
}

Impl :: struct {
  val: u8 = 42;
}

impl Proto for Impl {
  get :: (self: *Impl) -> *u8 {
    @self.val
  }
}

main :: () -> i32 {
  imp : Impl = .{};
  p : Proto = xx @imp;
  raw : *u8 = p.get();
  addr_word : u64 = xx raw;
  print("got pointer: {}\n", addr_word != 0);
  0
}
