mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic stack of sumtype push() (#16855)
This commit is contained in:
parent
2378b71f22
commit
0a6fc6d280
@ -458,7 +458,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||
return ast.void_type
|
||||
} else if left_value_sym.kind == .sum_type {
|
||||
if right_sym.kind != .array {
|
||||
if !c.table.is_sumtype_or_in_variant(left_value_type, ast.mktyp(right_type)) {
|
||||
if !c.table.is_sumtype_or_in_variant(left_value_type, ast.mktyp(c.unwrap_generic(right_type))) {
|
||||
c.error('cannot append `${right_sym.name}` to `${left_sym.name}`',
|
||||
right_pos)
|
||||
}
|
||||
|
@ -4,24 +4,3 @@ vlib/v/checker/tests/check_err_msg_with_generics.vv:15:10: error: cannot cast st
|
||||
15 | println(int(typ))
|
||||
| ~~~~~~~~
|
||||
16 | }
|
||||
vlib/datatypes/bstree.v:196:17: error: cannot append `T` to `[]T`
|
||||
194 | }
|
||||
195 | bst.in_order_traversal_helper(node.left, mut result)
|
||||
196 | result << node.value
|
||||
| ~~~~~
|
||||
197 | bst.in_order_traversal_helper(node.right, mut result)
|
||||
198 | }
|
||||
vlib/datatypes/bstree.v:216:17: error: cannot append `T` to `[]T`
|
||||
214 | bst.post_order_traversal_helper(node.left, mut result)
|
||||
215 | bst.post_order_traversal_helper(node.right, mut result)
|
||||
216 | result << node.value
|
||||
| ~~~~~
|
||||
217 | }
|
||||
218 |
|
||||
vlib/datatypes/bstree.v:232:17: error: cannot append `T` to `[]T`
|
||||
230 | return
|
||||
231 | }
|
||||
232 | result << node.value
|
||||
| ~~~~~
|
||||
233 | bst.pre_order_traversal_helper(node.left, mut result)
|
||||
234 | bst.pre_order_traversal_helper(node.right, mut result)
|
||||
|
21
vlib/v/tests/generics_stack_of_sumtype_push_test.v
Normal file
21
vlib/v/tests/generics_stack_of_sumtype_push_test.v
Normal file
@ -0,0 +1,21 @@
|
||||
import datatypes
|
||||
|
||||
type Content = bool | string
|
||||
|
||||
struct DataStack {
|
||||
mut:
|
||||
data datatypes.Stack[Content]
|
||||
}
|
||||
|
||||
fn (mut dstack DataStack) push(content Content) {
|
||||
dstack.data.push(content)
|
||||
}
|
||||
|
||||
fn test_generic_stack_of_sumtype_push() {
|
||||
mut dstack := DataStack{}
|
||||
dstack.push('hello')
|
||||
|
||||
println(dstack)
|
||||
assert dstack.data.len() == 1
|
||||
assert dstack.data.array() == [Content('hello')]
|
||||
}
|
Loading…
Reference in New Issue
Block a user