diff --git a/pythonbpf/expr/expr_pass.py b/pythonbpf/expr/expr_pass.py index b9984b8..a4a746f 100644 --- a/pythonbpf/expr/expr_pass.py +++ b/pythonbpf/expr/expr_pass.py @@ -842,5 +842,13 @@ def handle_expr( call, local_sym_tab, ) + elif any(isinstance(node, ast.Call) for node in ast.walk(call)): + # A docstring or a bare name has no effect and can be dropped; an + # expression with a call in it (`f() if c else g()`, `a() or b()`) + # does, and dropping it would silently lose the call. + raise NotImplementedError( + f"Unsupported expression statement on line {expr.lineno}: " + f"{type(call).__name__}; write it as an if statement or assignment" + ) else: - logger.info("Unsupported expression type") + logger.debug(f"Dropping expression statement without effect: {ast.dump(call)}") diff --git a/tests/test_config.toml b/tests/test_config.toml index 10ab94b..c935312 100644 --- a/tests/test_config.toml +++ b/tests/test_config.toml @@ -17,6 +17,8 @@ "failing_tests/conditionals/struct_value.py" = {reason = "A struct value has no truth value (C rejects `if (s)`): a compile error naming the struct", level = "ir"} +"failing_tests/conditionals/oneline.py" = {reason = "A conditional expression used as a statement (`f() if c else g()`) is not lowered: a compile error rather than silently dropping both calls; write it as an if statement", level = "ir"} + "failing_tests/return_struct.py" = {reason = "Returning a struct value from an integer function is a type error (nothing to dereference to an integer)", level = "ir"} "failing_tests/license.py" = {reason = "Missing LICENSE global produces IR that llc rejects — should be caught earlier with a clear error message", level = "llc"}