1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: make type_implements() return false if methods of interface didn't implement (#18076)

This commit is contained in:
Mark aka walkingdevel 2023-04-28 19:18:23 +00:00 committed by GitHub
parent 2f48288a25
commit 9eee131423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -914,6 +914,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
} }
// voidptr is an escape hatch, it should be allowed to be passed // voidptr is an escape hatch, it should be allowed to be passed
if utyp != ast.voidptr_type && utyp != ast.nil_type { if utyp != ast.voidptr_type && utyp != ast.nil_type {
mut are_methods_implemented := true
// Verify methods // Verify methods
for imethod in imethods { for imethod in imethods {
method := c.table.find_method_with_embeds(typ_sym, imethod.name) or { method := c.table.find_method_with_embeds(typ_sym, imethod.name) or {
@ -930,6 +932,7 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
typ_sym.find_method_with_generic_parent(imethod.name) or { typ_sym.find_method_with_generic_parent(imethod.name) or {
c.error("`${styp}` doesn't implement method `${imethod.name}` of interface `${inter_sym.name}`", c.error("`${styp}` doesn't implement method `${imethod.name}` of interface `${inter_sym.name}`",
pos) pos)
are_methods_implemented = false
continue continue
} }
} }
@ -944,6 +947,10 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
return false return false
} }
} }
if !are_methods_implemented {
return false
}
} }
// Verify fields // Verify fields
if mut inter_sym.info is ast.Interface { if mut inter_sym.info is ast.Interface {