cgen,table: fix generic interface used in an implements clause (fix #22161) (#22165)

This commit is contained in:
Felipe Pena 2024-09-06 02:03:44 -03:00 committed by GitHub
parent 9238dd6b31
commit ae9456adc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -2087,7 +2087,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
}
}
mut info := ts.info
info.is_generic = false
info.is_generic = final_concrete_types.any(it.has_flag(.generic))
info.concrete_types = final_concrete_types
info.parent_type = typ.set_flag(.generic)
info.fields = fields

View File

@ -0,0 +1,19 @@
interface Foo[T] {
val T
foo() T
}
struct Bar[T] implements Foo[T] {
val T
}
fn (b Bar[T]) foo() T {
return b.val
}
fn test_main() {
b := Bar{
val: 0
}
assert b.foo() == 0
}