Skip to content

Commit

Permalink
checker: add check for unknown generic types in type alias decl (#16377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Nov 10, 2022
1 parent 2634b99 commit bbd0603
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vlib/v/checker/checker.v
Expand Up @@ -444,6 +444,16 @@ pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
orig_sym := c.table.type_to_str(node.parent_type)
c.error('type `$typ_sym.str()` is an alias, use the original alias type `$orig_sym` instead',
node.type_pos)
} else if typ_sym.kind == .struct_ {
if mut typ_sym.info is ast.Struct {
// check if the generic param types have been defined
for ct in typ_sym.info.concrete_types {
ct_sym := c.table.sym(ct)
if ct_sym.kind == .placeholder {
c.error('unknown type `$ct_sym.name`', node.type_pos)
}
}
}
}
}

Expand Down
@@ -0,0 +1,7 @@
vlib/v/checker/tests/type_alias_struct_generic_unknown_name_err.vv:7:16: error: unknown type `UnknownType`
5 | }
6 |
7 | type NewType = Foo<UnknownType>
| ~~~~~~~~~~~~~~~~
8 |
9 | fn main() {
10 changes: 10 additions & 0 deletions vlib/v/checker/tests/type_alias_struct_generic_unknown_name_err.vv
@@ -0,0 +1,10 @@
module main

struct Foo<T> {
value T
}

type NewType = Foo<UnknownType>

fn main() {
}

0 comments on commit bbd0603

Please sign in to comment.