From 895af3e45c827b7586dd71bda561eea47acf8b40 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 21 Apr 2026 16:55:17 +0300 Subject: [PATCH] checker: fix ice when sorting an array of functions (fixes #10739) --- vlib/v/checker/infix.v | 10 ++++++++++ vlib/v/checker/tests/array_sort_function_type_err.out | 6 ++++++ vlib/v/checker/tests/array_sort_function_type_err.vv | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 vlib/v/checker/tests/array_sort_function_type_err.out create mode 100644 vlib/v/checker/tests/array_sort_function_type_err.vv diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index a9709b9b9..d9b6441e2 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -728,6 +728,16 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { } if left_sym.kind in [.array, .array_fixed] && right_sym.kind in [.array, .array_fixed] { c.error('only `==` and `!=` are defined on arrays', node.pos) + } else if left_sym.kind == .function || right_sym.kind == .function { + left_name := c.table.type_to_str(unwrapped_left_type) + right_name := c.table.type_to_str(unwrapped_right_type) + if left_sym.kind == .function && right_sym.kind == .function + && left_name == right_name { + c.error('undefined operation `${left_name}` ${node.op.str()} `${right_name}`', + left_right_pos) + } else { + c.error('mismatched types `${left_name}` and `${right_name}`', left_right_pos) + } } else if left_sym.info is ast.Struct && left_sym.info.generic_types.len > 0 { node.promoted_type = ast.bool_type return ast.bool_type diff --git a/vlib/v/checker/tests/array_sort_function_type_err.out b/vlib/v/checker/tests/array_sort_function_type_err.out new file mode 100644 index 000000000..625ca5153 --- /dev/null +++ b/vlib/v/checker/tests/array_sort_function_type_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/array_sort_function_type_err.vv:7:9: error: undefined operation `&fn ()` > `&fn ()` + 5 | fn main() { + 6 | mut x := [main, b, c] + 7 | x.sort(a > b) + | ~~~~~ + 8 | } diff --git a/vlib/v/checker/tests/array_sort_function_type_err.vv b/vlib/v/checker/tests/array_sort_function_type_err.vv new file mode 100644 index 000000000..9fb133e78 --- /dev/null +++ b/vlib/v/checker/tests/array_sort_function_type_err.vv @@ -0,0 +1,8 @@ +fn b() {} + +fn c() {} + +fn main() { + mut x := [main, b, c] + x.sort(a > b) +} -- 2.39.5