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

checker: add check for multi level fn aliases (#16361)

This commit is contained in:
Swastik Baranwal 2022-11-09 14:06:39 +05:30 committed by GitHub
parent ce79c9c876
commit 7830597b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -440,6 +440,10 @@ pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
node.type_pos)
} else if typ_sym.kind == .chan {
c.error('aliases of `chan` types are not allowed.', node.type_pos)
} else if typ_sym.kind == .function {
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)
}
}

View File

@ -0,0 +1,4 @@
vlib/v/checker/tests/nested_fn_alias_err.vv:2:12: error: type `Fn1` is an alias, use the original alias type `fn ()` instead
1 | type Fn1 = fn ()
2 | type Fn2 = Fn1
| ~~~

View File

@ -0,0 +1,2 @@
type Fn1 = fn ()
type Fn2 = Fn1