mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
table: fix generics struct with anon fn fields (#10024)
This commit is contained in:
parent
ac2eaa05c7
commit
a6764e3cc3
@ -63,7 +63,6 @@ pub fn (t &Table) panic(message string) {
|
|||||||
|
|
||||||
pub struct Fn {
|
pub struct Fn {
|
||||||
pub:
|
pub:
|
||||||
return_type Type
|
|
||||||
is_variadic bool
|
is_variadic bool
|
||||||
language Language
|
language Language
|
||||||
generic_names []string
|
generic_names []string
|
||||||
@ -79,10 +78,10 @@ pub:
|
|||||||
mod string
|
mod string
|
||||||
ctdefine string // compile time define. "myflag", when [if myflag] tag
|
ctdefine string // compile time define. "myflag", when [if myflag] tag
|
||||||
attrs []Attr
|
attrs []Attr
|
||||||
//
|
|
||||||
pos token.Position
|
pos token.Position
|
||||||
return_type_pos token.Position
|
return_type_pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
|
return_type Type
|
||||||
name string
|
name string
|
||||||
params []Param
|
params []Param
|
||||||
source_fn voidptr // set in the checker, while processing fn declarations
|
source_fn voidptr // set in the checker, while processing fn declarations
|
||||||
@ -1108,6 +1107,26 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
|
|||||||
}
|
}
|
||||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||||
}
|
}
|
||||||
|
} else if mut sym.info is FnType {
|
||||||
|
mut func := sym.info.func
|
||||||
|
if func.return_type.has_flag(.generic) {
|
||||||
|
if typ := t.resolve_generic_to_concrete(func.return_type, generic_names, concrete_types,
|
||||||
|
is_inst)
|
||||||
|
{
|
||||||
|
func.return_type = typ
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for mut param in func.params {
|
||||||
|
if param.typ.has_flag(.generic) {
|
||||||
|
if typ := t.resolve_generic_to_concrete(param.typ, generic_names, concrete_types,
|
||||||
|
is_inst)
|
||||||
|
{
|
||||||
|
param.typ = typ
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
idx := t.find_or_register_fn_type('', func, true, false)
|
||||||
|
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||||
}
|
}
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
14
vlib/v/tests/generics_struct_anon_fn_fields_test.v
Normal file
14
vlib/v/tests/generics_struct_anon_fn_fields_test.v
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
struct Scope<T> {
|
||||||
|
before fn () T
|
||||||
|
specs []fn (T) T
|
||||||
|
after fn (T)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generics_struct_anon_fn_fields() {
|
||||||
|
s := Scope<u32>{}
|
||||||
|
println(s)
|
||||||
|
ts := '$s'
|
||||||
|
assert ts.contains('before: fn () u32')
|
||||||
|
assert ts.contains('specs: []')
|
||||||
|
assert ts.contains('after: fn (u32)')
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user