Skip to content

Commit

Permalink
v.ast: allow for fn f()&IAbc{return voidptr(0)} with no additional …
Browse files Browse the repository at this point in the history
…voidptr implicit conversions to compile
  • Loading branch information
spytheman committed Jun 16, 2021
1 parent 862c4cf commit 69ce8ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,9 @@ fn (mut table Table) does_type_implement_interface(typ Type, inter_typ Type) boo
return false
}
inter_sym.info.types << utyp
if !inter_sym.info.types.contains(voidptr_type) {
inter_sym.info.types << voidptr_type
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
interface IAbc {
name string
xyz()
}

fn f(i &IAbc) string {
return '$i'
}

struct Abc {
name string
x int = 123
}

fn (a Abc) xyz() {}

fn resource__null() &IAbc {
return voidptr(0)
}

fn test_fn_returning_voidptr_casted_as_interface_works() {
pi := resource__null()
assert f(pi) == '&IAbc(0)'
}

0 comments on commit 69ce8ba

Please sign in to comment.