diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index e7eda000bf..6da76c1b94 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -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 } diff --git a/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v b/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v new file mode 100644 index 0000000000..c66585e9c6 --- /dev/null +++ b/vlib/v/tests/interface_edge_cases/fn_returning_voidptr_casted_as_interface_test.v @@ -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)' +}