Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix unwrap when generic structs are used as arguments in uncalled methods(fix #20132) #20135

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,23 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
generic_names := struct_sym.info.generic_types.map(c.table.sym(it).name)
node.typ = c.table.unwrap_generic_type(node.typ, generic_names, concrete_types)
}
} else if struct_sym.info.generic_types.len > 0
&& struct_sym.info.generic_types.len == struct_sym.info.concrete_types.len
&& c.table.cur_concrete_types.len == 0 {
parent_type := struct_sym.info.parent_type
parent_sym := c.table.sym(parent_type)
for method in parent_sym.methods {
generic_names := struct_sym.info.generic_types.map(c.table.sym(it).name)
for i, param in method.params {
if i == 0 || !param.typ.has_flag(.generic) {
continue
}
param_sym := c.table.sym(param.typ)
if param_sym.kind in [.struct_, .interface_, .sum_type] {
c.table.unwrap_generic_type(param.typ, generic_names, struct_sym.info.concrete_types)
}
}
}
}
}
return node.typ
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
struct Param[T] {
}

struct Struct[T] {
}

pub fn (s Struct[T]) method[T](p Param[T]) {
}

fn test_main() {
_ = Struct[int]{}
assert true
// NOTE:
// Do not test call Struct.method() here,
// to test unwrap of generic struct parameters when the method is not called.
// test results only need to can compile.
}