v.checker: allow for a `f(unsafe{voidptr(0)})` call of `fn f(x &Interface){}`
parent
2f9e03b360
commit
e7cc93a120
|
@ -2698,8 +2698,11 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.error("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`",
|
// voidptr is an escape hatch, it should be allowed to be passed
|
||||||
pos)
|
if utyp != ast.voidptr_type {
|
||||||
|
c.error("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`",
|
||||||
|
pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Verify fields
|
// Verify fields
|
||||||
if mut inter_sym.info is ast.Interface {
|
if mut inter_sym.info is ast.Interface {
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
interface IAbc {
|
||||||
|
xyz()
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Abc {}
|
||||||
|
|
||||||
|
fn (a Abc) xyz() {}
|
||||||
|
|
||||||
|
fn f(i &IAbc) string {
|
||||||
|
return '$i'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_passing_voidptr_as_an_interface_reference() {
|
||||||
|
i := IAbc(Abc{})
|
||||||
|
assert f(&i) == '&IAbc(Abc{})'
|
||||||
|
// a voidptr() cast is an escape hatch, that should be allowed
|
||||||
|
// but perhaps it should be forced by the compiler to be in unsafe{}
|
||||||
|
assert f(unsafe { voidptr(0) }) == '&IAbc(0)'
|
||||||
|
}
|
Loading…
Reference in New Issue