protocols

This commit is contained in:
agra
2026-02-24 19:46:17 +02:00
parent 9dba8eef5b
commit 06d10541da
5 changed files with 431 additions and 1 deletions

View File

@@ -6078,8 +6078,16 @@ pub const CodeGen = struct {
// xx prefix: unwrap and convert freely (explicit cast)
if (node.data == .unary_op and node.data.unary_op.op == .xx) {
const inner = node.data.unary_op.operand;
const val = try self.genExpr(inner);
var val = try self.genExpr(inner);
const src_ty = self.inferType(inner);
// genExpr on struct literals returns an alloca (ptr), not a loaded value.
// Load it so convertValue/buildProtocolValue sees the actual struct value.
if (inner.data == .struct_literal and src_ty.isStruct()) {
const sname = self.resolveAlias(src_ty.struct_type);
if (self.lookupStructInfo(sname)) |si| {
val = c.LLVMBuildLoad2(self.builder, si.llvm_type.?, val, "xx_struct_load");
}
}
return self.convertValue(val, src_ty, target_ty);
}