| 1280 | program.name |
| 1281 | ); |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /// A struct field holding a function pointer is called as an expression |
| 1286 | /// (`db.op(args)`), lowering to a field load plus an indirect call. |
| 1287 | #[test] |
| 1288 | fn struct_function_pointer_field_call() { |
| 1289 | let (_, outcome, _) = run_hll( |
| 1290 | r#" |
| 1291 | type BinaryOp = (i32, i32) -> i32 |
| 1292 | add: (a: i32, b: i32) -> i32 { return a + b } |
| 1293 | mul: (a: i32, b: i32) -> i32 { return a * b } |
| 1294 | struct Ops { combine: BinaryOp } |
| 1295 | main: () -> i32 { |
| 1296 | ops: Ops = Ops { .combine = add } |
| 1297 | if ops.combine(20, 22) != 42 { return 1 } |
| 1298 | ops.combine = mul |
| 1299 | if ops.combine(6, 7) != 42 { return 2 } |
| 1300 | return 0 |
| 1301 | } |