fix everything except autofree
parent
30755f45b2
commit
c4e319447d
|
|
@ -23,6 +23,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||
c.expected_type = c.expr(node.left[i])
|
||||
}
|
||||
right_type := c.expr(right)
|
||||
c.fail_if_unreadable(right, right_type, 'right-hand side of assignment')
|
||||
if i == 0 {
|
||||
right_type0 = right_type
|
||||
node.right_types = [
|
||||
|
|
@ -114,7 +115,6 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||
}
|
||||
mut right := if i < node.right.len { node.right[i] } else { node.right[0] }
|
||||
mut right_type := node.right_types[i]
|
||||
c.fail_if_unreadable(right, right_type, 'right-hand side of assignment')
|
||||
if mut right is ast.Ident {
|
||||
right_sym := c.table.sym(right_type)
|
||||
if right_sym.info is ast.Struct {
|
||||
|
|
@ -186,7 +186,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||
}
|
||||
// Do not allow `a := 0; b := 0; a = &b`
|
||||
if !is_decl && left is ast.Ident && !is_blank_ident && !left_type.is_real_pointer()
|
||||
&& right_type.is_real_pointer() {
|
||||
&& right_type.is_real_pointer() && !right_type.has_flag(.shared_f) {
|
||||
left_sym := c.table.sym(left_type)
|
||||
if left_sym.kind != .function {
|
||||
c.warn(
|
||||
|
|
|
|||
|
|
@ -4194,8 +4194,10 @@ pub fn (mut c Checker) fail_if_unreadable(expr ast.Expr, typ ast.Type, what stri
|
|||
if expr.is_method {
|
||||
c.fail_if_unreadable(expr.left, expr.left_type, what)
|
||||
}
|
||||
return
|
||||
}
|
||||
ast.LockExpr {
|
||||
// TODO: check expressions inside the lock by appending to c.(r)locked_names
|
||||
return
|
||||
}
|
||||
ast.IndexExpr {
|
||||
|
|
|
|||
|
|
@ -1741,11 +1741,12 @@ fn (mut c Checker) map_builtin_method_call(mut node ast.CallExpr, left_type ast.
|
|||
if method_name[0] == `m` {
|
||||
c.fail_if_immutable(node.left)
|
||||
}
|
||||
if node.left.is_auto_deref_var() {
|
||||
if node.left.is_auto_deref_var() || ret_type.has_flag(.shared_f) {
|
||||
ret_type = left_type.deref()
|
||||
} else {
|
||||
ret_type = left_type
|
||||
}
|
||||
ret_type = ret_type.clear_flag(.shared_f)
|
||||
}
|
||||
'keys' {
|
||||
info := left_sym.info as ast.Map
|
||||
|
|
@ -1877,6 +1878,9 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
|||
} else {
|
||||
node.return_type = node.receiver_type.set_nr_muls(0)
|
||||
}
|
||||
if node.return_type.has_flag(.shared_f) {
|
||||
node.return_type = node.return_type.clear_flag(.shared_f)
|
||||
}
|
||||
} else if method_name == 'sort' {
|
||||
node.return_type = ast.void_type
|
||||
} else if method_name == 'contains' {
|
||||
|
|
|
|||
|
|
@ -503,6 +503,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
|
|||
elem_type_str := g.typ(info.elem_type)
|
||||
g.empty_line = true
|
||||
noscan := g.check_noscan(info.elem_type)
|
||||
g.writeln('$styp $tmp = {0};')
|
||||
has_infix_left_var_name := g.infix_left_var_name.len > 0
|
||||
if has_infix_left_var_name {
|
||||
g.writeln('if ($g.infix_left_var_name) {')
|
||||
|
|
@ -521,7 +522,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
|
|||
}
|
||||
g.writeln(';')
|
||||
g.writeln('int ${tmp}_len = ${tmp}_orig.len;')
|
||||
g.writeln('$styp $tmp = __new_array${noscan}(0, ${tmp}_len, sizeof($elem_type_str));\n')
|
||||
g.writeln('$tmp = __new_array${noscan}(0, ${tmp}_len, sizeof($elem_type_str));\n')
|
||||
i := g.new_tmp_var()
|
||||
g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {')
|
||||
g.indent++
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ fn test_filter() {
|
|||
|
||||
fn test_shared_filter() {
|
||||
shared arr := [3, 6, 1, 8, 2, 4, 5, 7]
|
||||
filtered := arr.filter(it > 4)
|
||||
|
||||
filtered := rlock arr {
|
||||
arr.filter(it > 4)
|
||||
}
|
||||
assert filtered.len == 4
|
||||
assert filtered.contains(6)
|
||||
assert filtered.contains(8)
|
||||
|
|
|
|||
Loading…
Reference in New Issue