Skip to content

Commit f90fcb5

Browse files
committed
all: more deref fixes (p. 2)
1 parent 28fb4e6 commit f90fcb5

9 files changed

Lines changed: 23 additions & 37 deletions

File tree

vlib/datatypes/bstree.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn (mut node BSTreeNode[T]) bind(mut to_bind BSTreeNode[T], _left bool) {
5151
node.right = to_bind.right
5252
node.value = to_bind.value
5353
node.is_init = to_bind.is_init
54-
to_bind = new_none_node[T](false)
54+
to_bind = *new_none_node[T](false)
5555
}
5656

5757
// Pure Binary Seach Tree implementation
@@ -140,7 +140,7 @@ fn (mut bst BSTree[T]) remove_helper(mut node BSTreeNode[T], value T, left bool)
140140
} else {
141141
parent.right = new_none_node[T](false)
142142
}
143-
node = new_none_node[T](false)
143+
node = *new_none_node[T](false)
144144
}
145145
return true
146146
}

vlib/v/checker/tests/check_err_msg_with_generics.out

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
vlib/datatypes/bstree.v:54:10: warning: cannot assign a reference to a value (this will be an error soon) left=datatypes.BSTreeNode[Result[[]Token, Err[string]]] false right=datatypes.BSTreeNode[Result[[]Token, Err[string]]] true ptr=true
2-
52 | node.value = to_bind.value
3-
53 | node.is_init = to_bind.is_init
4-
54 | to_bind = new_none_node[T](false)
5-
| ^
6-
55 | }
7-
56 |
8-
vlib/datatypes/bstree.v:143:9: warning: cannot assign a reference to a value (this will be an error soon) left=datatypes.BSTreeNode[Result[[]Token, Err[string]]] false right=datatypes.BSTreeNode[Result[[]Token, Err[string]]] true ptr=true
9-
141 | parent.right = new_none_node[T](false)
10-
142 | }
11-
143 | node = new_none_node[T](false)
12-
| ^
13-
144 | }
14-
145 | return true
151
vlib/v/checker/tests/check_err_msg_with_generics.vv:15:10: error: cannot cast struct `datatypes.BSTree[Result[[]Token, Err[string]]]` to `int`
162
13 | fn test_err_msg() {
173
14 | typ := datatypes.BSTree[Result[[]Token, Err[string]]]{}
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +0,0 @@
1-
vlib/datatypes/bstree.v:54:10: warning: cannot assign a reference to a value (this will be an error soon) left=datatypes.BSTreeNode[KeyVal[int]] false right=datatypes.BSTreeNode[KeyVal[int]] true ptr=true
2-
52 | node.value = to_bind.value
3-
53 | node.is_init = to_bind.is_init
4-
54 | to_bind = new_none_node[T](false)
5-
| ^
6-
55 | }
7-
56 |
8-
vlib/datatypes/bstree.v:143:9: warning: cannot assign a reference to a value (this will be an error soon) left=datatypes.BSTreeNode[KeyVal[int]] false right=datatypes.BSTreeNode[KeyVal[int]] true ptr=true
9-
141 | parent.right = new_none_node[T](false)
10-
142 | }
11-
143 | node = new_none_node[T](false)
12-
| ^
13-
144 | }
14-
145 | return true

vlib/v/gen/c/assign.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@ fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
20372037
g.write('${styp} _var_${left.pos.pos} = ${string_clone}*(${styp}*)builtin__array_get(')
20382038
}
20392039

2040-
if left.left_type.is_ptr() {
2040+
if left.left_type.is_ptr() || left.left.is_auto_deref_var() {
20412041
g.write('*')
20422042
}
20432043
g.expr(left.left)

vlib/v/gen/c/dumpexpr.v

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
5555
if node.expr.info is ast.IdentVar {
5656
current_fn_ident_type := g.resolve_current_fn_generic_param_type(node.expr.name)
5757
if current_fn_ident_type != 0 {
58-
expr_type = current_fn_ident_type
58+
is_auto_deref := node.expr.obj is ast.Var && node.expr.obj.is_auto_deref
59+
expr_type = if is_auto_deref && current_fn_ident_type.is_ptr() {
60+
current_fn_ident_type.deref()
61+
} else {
62+
current_fn_ident_type
63+
}
5964
} else {
6065
resolved_ident_type := g.unwrap_generic(g.type_resolver.get_type_or_default(ast.Expr(node.expr),
6166
expr_type))
@@ -181,7 +186,12 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
181186
if !is_comptime_smartcast {
182187
current_fn_ident_type := g.resolve_current_fn_generic_param_type(node.expr.name)
183188
if current_fn_ident_type != 0 {
184-
expr_type = current_fn_ident_type
189+
is_auto_deref := node.expr.obj is ast.Var && node.expr.obj.is_auto_deref
190+
expr_type = if is_auto_deref && current_fn_ident_type.is_ptr() {
191+
current_fn_ident_type.deref()
192+
} else {
193+
current_fn_ident_type
194+
}
185195
name = g.styp(expr_type.clear_flags(.shared_f, .result)).replace('*',
186196
'')
187197
}
@@ -232,6 +242,10 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) {
232242
if expr_type.has_flag(.option_mut_param_t) {
233243
g.write('*')
234244
}
245+
if node.expr is ast.Ident && node.expr.obj is ast.Var && node.expr.obj.is_auto_deref
246+
&& !expr_type.is_ptr() {
247+
g.write('*')
248+
}
235249
for {
236250
if node.expr is ast.Ident {
237251
if node.expr.obj is ast.Var {

vlib/v/gen/c/index.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
222222
info.elem_type
223223
}
224224
elem_sym := g.table.final_sym(elem_type)
225-
left_is_ptr := array_left_type.is_ptr()
225+
left_is_ptr := array_left_type.is_ptr() || node.left.is_auto_deref_var()
226226
result_type := match true {
227227
gen_or && elem_type.has_flag(.option) {
228228
node.typ.clear_flag(.option)

vlib/v/gen/native/blacklist.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const blacklist = {
5757
'string.contains_u8': false
5858
'malloc_noscan': false
5959
'malloc': false
60+
'malloc_uninit': false
6061
'is_nil': false
6162
'memdup': false
6263
'vcalloc': false

vlib/v/generics/new_generics_regression_test.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn run_new_generic_solver_tests(root_label string, test_cmd string, expected_sum
9898
}
9999

100100
const expected_summsvc_generics = 'Summary for all V _test.v files: 108 failed, 166 passed, 274 total.'
101-
const expected_summary_generics = 'Summary for all V _test.v files: 107 failed, 167 passed, 274 total.'
101+
const expected_summary_generics = 'Summary for all V _test.v files: 106 failed, 168 passed, 274 total.'
102102
const expected_summsvc_vec = 'Summary for all V _test.v files: 3 failed, 3 total.'
103103
const expected_summary_vec = 'Summary for all V _test.v files: 3 failed, 3 total.'
104104
const expected_summsvc_flag = 'Summary for all V _test.v files: 2 failed, 17 passed, 19 total.'
@@ -212,7 +212,6 @@ const failing_tests = [
212212
'vlib/v/tests/generics/generics_with_nested_generic_method_call_test.v',
213213
'vlib/v/tests/generics/generics_with_nested_generics_fn_infer_call_test.v',
214214
'vlib/v/tests/generics/generics_with_pointer_index_test.v',
215-
'vlib/v/tests/generics/generics_with_recursive_generics_fn_test.v',
216215
]!
217216
const failing_math_vec_tests = [
218217
'vlib/math/vec/vec2_test.v',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[vlib/v/slow_tests/inout/dump_generic_fn_mut_arg.vv:11] t: &Reptile{}
1+
[vlib/v/slow_tests/inout/dump_generic_fn_mut_arg.vv:11] t: Reptile{}

0 commit comments

Comments
 (0)