From 0c183da116d6265774a5e177068b3010882b2222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Thu, 20 Aug 2020 16:29:40 +0200 Subject: [PATCH] checker: fix sort return type (#6182) --- vlib/v/checker/checker.v | 2 ++ vlib/v/gen/cgen.v | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 473513cb80..323f6edd2c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -910,6 +910,8 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type { // in ['clone', 'str'] { call_expr.receiver_type = left_type.to_ptr() // call_expr.return_type = call_expr.receiver_type + } else if method_name == 'sort' { + call_expr.return_type = table.void_type } return call_expr.return_type } else if left_type_sym.kind == .map && method_name == 'clone' { diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 647b35b16d..71ea236d5c 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3907,14 +3907,14 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) { // `users.sort(a.age < b.age)` fn (mut g Gen) gen_array_sort(node ast.CallExpr) { // println('filter s="$s"') - return_sym := g.table.get_type_symbol(node.return_type) - if return_sym.kind != .array { + rec_sym := g.table.get_type_symbol(node.receiver_type) + if rec_sym.kind != .array { println(node.name) println(g.typ(node.receiver_type)) - // println(sym.kind) - verror('sort() requires an array') + // println(rec_sym.kind) + verror('.sort() is an array method') } - info := return_sym.info as table.Array + info := rec_sym.info as table.Array // No arguments means we are sorting an array of builtins (e.g. `numbers.sort()`) // The type for the comparison fns is the type of the element itself. mut typ := info.elem_type