| 1300 | return 0 |
| 1301 | } |
| 1302 | "#, |
| 1303 | ); |
| 1304 | assert!( |
| 1305 | matches!(outcome, RunOutcome::Halted(0)), |
| 1306 | "struct fn-pointer field call should pass, got {outcome:?}" |
| 1307 | ); |
| 1308 | } |
| 1309 | |
| 1310 | /// An indexed function-pointer element is callable directly: `table[i](args)`. |
| 1311 | #[test] |
| 1312 | fn indexed_function_pointer_call() { |
| 1313 | let (_, outcome, _) = run_hll( |
| 1314 | r#" |
| 1315 | type BinaryOp = (i32, i32) -> i32 |
| 1316 | add: (a: i32, b: i32) -> i32 { return a + b } |
| 1317 | mul: (a: i32, b: i32) -> i32 { return a * b } |
| 1318 | main: () -> i32 { |
| 1319 | ops: BinaryOp[2] = [add, mul] |
| 1320 | if ops[0](40, 2) != 42 { return 1 } |
| 1321 | if ops[1](6, 7) != 42 { return 2 } |