mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Core: Reject a struct value as a condition with a clear error
`if dat:` on a local struct built Constant(struct_type, 0) in convert_to_bool, and llvmlite failed later, while printing the module, with "'int' object is not iterable". A struct has no truth value (C rejects `if (s)`; Python would call any object true), so it is now a TypeError that says to test a field. A pointer to a struct is unaffected. The xfail was named struct_ptr but tests a struct value; it is renamed to struct_value.py and becomes a negative test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -113,6 +113,14 @@ def convert_to_bool(builder, val):
|
||||
"""Convert a value to boolean."""
|
||||
if val.type == ir.IntType(1):
|
||||
return val
|
||||
if not isinstance(val.type, (ir.IntType, ir.PointerType)):
|
||||
# C rejects `if (s)` on a struct, and Python would call any object
|
||||
# true; either way it is never what was meant.
|
||||
kind = "struct" if isinstance(val.type, ir.BaseStructType) else "value"
|
||||
raise TypeError(
|
||||
f"a {kind} of type {val.type} has no truth value: test one of its "
|
||||
"fields instead"
|
||||
)
|
||||
if isinstance(val.type, ir.PointerType):
|
||||
zero = ir.Constant(val.type, None)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user