Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Oct 7, 2024
1 parent 87a4eb1 commit ff285bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -4976,7 +4976,7 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
return name
}

fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos token.Pos) bool {
fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos token.Pos, is_container bool) bool {
if typ == 0 {
c.error('unknown type', pos)
return false
Expand All @@ -5002,11 +5002,13 @@ fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos toke
match sym.kind {
.function {
fn_info := sym.info as ast.FnType
if !c.ensure_generic_type_specify_type_names(fn_info.func.return_type, fn_info.func.return_type_pos) {
if !c.ensure_generic_type_specify_type_names(fn_info.func.return_type, fn_info.func.return_type_pos,
is_container) {
return false
}
for param in fn_info.func.params {
if !c.ensure_generic_type_specify_type_names(param.typ, param.type_pos) {
if !c.ensure_generic_type_specify_type_names(param.typ, param.type_pos,
is_container) {
return false
}
}
Expand All @@ -5018,28 +5020,29 @@ fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos toke
}
.array {
if !c.ensure_generic_type_specify_type_names((sym.info as ast.Array).elem_type,
pos) {
pos, true) {
return false
}
}
.array_fixed {
if !c.ensure_generic_type_specify_type_names((sym.info as ast.ArrayFixed).elem_type,
pos) {
pos, true) {
return false
}
}
.map {
info := sym.info as ast.Map
if !c.ensure_generic_type_specify_type_names(info.key_type, pos) {
if !c.ensure_generic_type_specify_type_names(info.key_type, pos, true) {
return false
}
if !c.ensure_generic_type_specify_type_names(info.value_type, pos) {
if !c.ensure_generic_type_specify_type_names(info.value_type, pos, true) {
return false
}
}
.sum_type {
info := sym.info as ast.SumType
if info.generic_types.len > 0 && info.concrete_types.len == 0 {
if info.generic_types.len > 0 && (is_container || !typ.has_flag(.generic))
&& info.concrete_types.len == 0 {
c.error('`${sym.name}` type is generic sumtype, must specify the generic type names, e.g. ${sym.name}[T], ${sym.name}[int]',
pos)
return false
Expand All @@ -5063,7 +5066,7 @@ fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos toke
}
.alias {
info := sym.info as ast.Alias
if !c.ensure_generic_type_specify_type_names(info.parent_type, pos) {
if !c.ensure_generic_type_specify_type_names(info.parent_type, pos, is_container) {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
if !c.ensure_type_exists(field.typ, field.type_pos) {
continue
}
if !c.ensure_generic_type_specify_type_names(field.typ, field.type_pos) {
if !c.ensure_generic_type_specify_type_names(field.typ, field.type_pos, false) {
continue
}
if field.typ.has_flag(.generic) {
Expand Down

0 comments on commit ff285bb

Please sign in to comment.