checker: fix sort return type (#6182)

pull/6130/head
Daniel Däschle 2020-08-20 16:29:40 +02:00 committed by GitHub
parent e8ff94fb8b
commit 0c183da116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -910,6 +910,8 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
// in ['clone', 'str'] { // in ['clone', 'str'] {
call_expr.receiver_type = left_type.to_ptr() call_expr.receiver_type = left_type.to_ptr()
// call_expr.return_type = call_expr.receiver_type // 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 return call_expr.return_type
} else if left_type_sym.kind == .map && method_name == 'clone' { } else if left_type_sym.kind == .map && method_name == 'clone' {

View File

@ -3907,14 +3907,14 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
// `users.sort(a.age < b.age)` // `users.sort(a.age < b.age)`
fn (mut g Gen) gen_array_sort(node ast.CallExpr) { fn (mut g Gen) gen_array_sort(node ast.CallExpr) {
// println('filter s="$s"') // println('filter s="$s"')
return_sym := g.table.get_type_symbol(node.return_type) rec_sym := g.table.get_type_symbol(node.receiver_type)
if return_sym.kind != .array { if rec_sym.kind != .array {
println(node.name) println(node.name)
println(g.typ(node.receiver_type)) println(g.typ(node.receiver_type))
// println(sym.kind) // println(rec_sym.kind)
verror('sort() requires an array') 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()`) // 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. // The type for the comparison fns is the type of the element itself.
mut typ := info.elem_type mut typ := info.elem_type