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:
parent
aeebb4f118
commit
e48b55fc80
@ -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)
|
||||
|
6
vlib/v/checker/tests/result_alias_type_err.out
Normal file
6
vlib/v/checker/tests/result_alias_type_err.out
Normal 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
|
3
vlib/v/checker/tests/result_alias_type_err.vv
Normal file
3
vlib/v/checker/tests/result_alias_type_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
type Abc = !int
|
||||
|
||||
dump(Abc(5))
|
Loading…
Reference in New Issue
Block a user