0 issues 1 contributor 4 branches 0 releases
Additions: 40 Deletions: 7 View patch
1 return sr
2 }
3
4-struct SignResult {
5+pub struct SignResult {
6 mut:
7 item string
8 result bool
9
1 ```v
2 import sync.pool
3
4-struct SResult {
5+pub struct SResult {
6 s string
7 }
8
9
1 from_sym := c.table.sym(from_type)
2 final_from_sym := c.table.final_sym(from_type)
3
4- mut to_type := node.typ
5+ mut to_type := c.unwrap_generic(node.typ)
6 mut to_sym := c.table.sym(to_type) // type to be used as cast
7 mut final_to_sym := c.table.final_sym(to_type)
8
9 }
10 }
11 }
12- node.typname = c.table.sym(to_type).name
13- return to_type
14+ node.typname = c.table.sym(node.typ).name
15+ return node.typ
16 }
17
18 fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
19
1new file mode 100644
2+vlib/v/checker/tests/cast_voidptr_to_struct_err.vv:6:9: error: cannot cast `voidptr` to struct
3+ 4 |
4+ 5 | fn unwrap_concrete(ptr voidptr) Foo {
5+ 6 | return Foo(ptr)
6+ | ~~~~~~~~
7+ 7 | }
8+ 8 |
9+vlib/v/checker/tests/cast_voidptr_to_struct_err.vv:10:9: error: cannot cast `voidptr` to struct
10+ 8 |
11+ 9 | fn unwrap_generic<T>(ptr voidptr) T {
12+ 10 | return T(ptr)
13+ | ~~~~~~
14+ 11 | }
15+ 12 |
16
1new file mode 100644
2+struct Foo {
3+ x int
4+}
5+
6+fn unwrap_concrete(ptr voidptr) Foo {
7+ return Foo(ptr)
8+}
9+
10+fn unwrap_generic<T>(ptr voidptr) T {
11+ return T(ptr)
12+}
13+
14+pub fn main() {
15+ foo1 := unwrap_concrete(voidptr(0))
16+ foo2 := unwrap_generic<Foo>(voidptr(0))
17+
18+ println(foo1)
19+ println(foo2)
20+}
21
1 return res
2 }
3
4-struct Gen {
5+pub struct Gen {
6 pref &pref.Preferences
7 field_data_type ast.Type // cache her to avoid map lookups
8 module_built string
9
1 fn test_infer_generic_interface() {
2 s := Struct<u32>{7, 5}
3 println(s)
4- i := Interface(s)
5+ i := Interface<u32>(s)
6 println(i)
7 assert i.method() == 10
8 }
9