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

checker: disallow Result type aliases (#18693)

This commit is contained in:
Swastik Baranwal 2023-06-27 22:38:37 +05:30 committed by GitHub
parent aeebb4f118
commit e48b55fc80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -462,6 +462,10 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
}
c.ensure_type_exists(node.parent_type, node.type_pos) or { return }
mut parent_typ_sym := c.table.sym(node.parent_type)
if node.parent_type.has_flag(.result) {
c.add_error_detail('Result types cannot be stored and have to be unwrapped immediately')
c.error('cannot make an alias of Result type', node.type_pos)
}
match parent_typ_sym.kind {
.placeholder, .int_literal, .float_literal {
c.error('unknown aliased type `${parent_typ_sym.name}`', node.type_pos)

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/result_alias_type_err.vv:1:12: error: cannot make an alias of Result type
1 | type Abc = !int
| ~~~~
2 |
3 | dump(Abc(5))
Details: Result types cannot be stored and have to be unwrapped immediately

View File

@ -0,0 +1,3 @@
type Abc = !int
dump(Abc(5))