File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -4755,7 +4755,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
4755
4755
styp := g.base_type (fn_ret_type)
4756
4756
g.writeln ('${ret_typ} ${tmpvar} ;' )
4757
4757
g.write ('_option_ok(&(${styp} []) { ' )
4758
- if ! fn_ret_type.is_ptr () && node.types[0 ].is_ptr () {
4758
+ if ! g. unwrap_generic ( fn_ret_type) .is_ptr () && node.types[0 ].is_ptr () {
4759
4759
if ! (node.exprs[0 ] is ast.Ident && ! g.is_amp) {
4760
4760
g.write ('*' )
4761
4761
}
Original file line number Diff line number Diff line change
1
+ struct ObjectDesc {
2
+ typ u32
3
+ ptr voidptr
4
+ }
5
+
6
+ struct ABCD {}
7
+
8
+ pub fn cast_object_desc [H](desc & ObjectDesc) ? H {
9
+ $if H is & ABCD {
10
+ if desc.typ == 12 { // desc == ABCD
11
+ return & ABCD (desc.ptr)
12
+ }
13
+ }
14
+ return none
15
+ }
16
+
17
+ fn test_main () {
18
+ obj := ABCD{}
19
+ a := cast_object_desc[& ABCD](ObjectDesc{ typ: 12 , ptr: voidptr (& obj) })
20
+ dump (a)
21
+ assert * a? == obj
22
+ }
You can’t perform that action at this time.
0 commit comments