1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add check for unknown generic types in type alias decl (#16377)

This commit is contained in:
Swastik Baranwal 2022-11-10 07:38:00 +05:30 committed by GitHub
parent 2634b99769
commit bbd0603b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -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)
}
}
}
}
}

View File

@ -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() {

View File

@ -0,0 +1,10 @@
module main
struct Foo<T> {
value T
}
type NewType = Foo<UnknownType>
fn main() {
}