Core: Return through the same value path as every other consumer

A pointer used where a value is expected is dereferenced to it, with a
null check, in helper arguments, printk arguments, binary-operation
operands and comparisons, all through deref_to_depth. return was the
one consumer that never joined that convention, so `return p` on a map
lookup emitted `ret i64*` and left it to llc to reject. handle_return
now goes through get_typed_operand, which is that path, and converts
the result to the declared return type like the augmented-assignment
store does.

convert() no longer passes a non-integer through silently: every
caller either checks both sides or is on an integer-only path, so what
reaches that branch is a type error, and it is raised with both types
named instead of surfacing from llc with an IR line number. Returning
a struct value is the case that now fails at compile time.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Pragyansh Chaturvedi
2026-09-18 17:52:23 +05:30
parent 359ddbd031
commit 8e802e8532
2 changed files with 14 additions and 9 deletions

View File

@ -53,7 +53,12 @@ def convert(builder, val, from_ty, to_ty):
value itself, which may already be wider than its descriptor says.
"""
if not (isinstance(to_ty, ir.IntType) and isinstance(val.type, ir.IntType)):
return val
# Every caller either checks both sides are integers or sits on a path
# that only carries integers, so reaching here is a type error that
# would otherwise surface as an llc rejection with no Python line.
raise TypeError(
f"integer conversion requested for a {val.type} value to {to_ty}"
)
if val.type.width > to_ty.width:
return builder.trunc(val, to_ty)
if val.type.width < to_ty.width: