checker: forbid aliasing an alias (#6118)

pull/6144/head
Enzo 2020-08-16 04:53:16 +02:00 committed by GitHub
parent bf065674cc
commit a02593204f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -266,6 +266,10 @@ pub fn (mut c Checker) type_decl(node ast.TypeDecl) {
typ_sym := c.table.get_type_symbol(node.parent_type)
if typ_sym.kind == .placeholder {
c.error("type `$typ_sym.name` doesn't exist", node.pos)
} else if typ_sym.kind == .alias {
orig_sym := c.table.get_type_symbol((typ_sym.info as table.Alias).parent_type)
c.error('type `$typ_sym.name` is an alias, use the original alias type `$orig_sym.name` instead',
node.pos)
}
}
ast.FnTypeDecl {

View File

@ -0,0 +1,4 @@
vlib/v/checker/tests/nested_aliases.v:2:1: error: type `MyInt` is an alias, use the original alias type `int` instead
1 | type MyInt = int
2 | type MyMyInt = MyInt
| ~~~~~~~~~~~~

View File

@ -0,0 +1,2 @@
type MyInt = int
type MyMyInt = MyInt