fix(lower): diagnose .* on a non-pointer instead of codegen panic

`lowerDerefExpr` left the deref's result type `.unresolved` when the
operand wasn't a pointer (e.g. a stale `value.*` after a parameter
changed from `*T` to `T`), and emitted the `.deref` anyway. That
unresolved type slipped through to emit_llvm's "unresolved type reached
LLVM emission" panic with no source location.

Now it emits a clean diagnostic at the deref site
("cannot dereference with `.*`: 'T' is not a pointer") and recovers.
Regression: examples/254-deref-non-pointer-reject.sx.
This commit is contained in:
agra
2026-06-01 17:37:27 +03:00
parent 5d275ee274
commit 497d450ba7
4 changed files with 30 additions and 4 deletions

View File

@@ -5483,16 +5483,22 @@ pub const Lowering = struct {
fn lowerDerefExpr(self: *Lowering, de: *const ast.DerefExpr) Ref {
const ptr = self.lowerExpr(de.operand);
// Resolve pointee type from the pointer type
// Resolve pointee type from the pointer type.
const ptr_ty = self.inferExprType(de.operand);
var pointee_ty: TypeId = .unresolved;
if (!ptr_ty.isBuiltin()) {
const info = self.module.types.get(ptr_ty);
if (info == .pointer) {
pointee_ty = info.pointer.pointee;
return self.builder.emit(.{ .deref = .{ .operand = ptr } }, info.pointer.pointee);
}
}
return self.builder.emit(.{ .deref = .{ .operand = ptr } }, pointee_ty);
// Operand isn't a pointer — `.*` is invalid. Diagnose here instead of
// emitting a `.deref` with an `.unresolved` result type, which would
// otherwise slip through to emit_llvm's "unresolved type reached LLVM
// emission" panic with no source location.
if (self.diagnostics) |d| {
d.addFmt(.err, de.operand.span, "cannot dereference with `.*`: '{s}' is not a pointer", .{self.formatTypeName(ptr_ty)});
}
return ptr;
}
fn lowerForceUnwrap(self: *Lowering, fu: *const ast.ForceUnwrap) Ref {