mirror of
https://github.com/vlang/v.git
synced 2025-09-11 16:36:20 -04:00
parser: disallow option alias with option parent type (#20769)
This commit is contained in:
parent
99579acaf2
commit
4d01a779b6
@ -534,6 +534,13 @@ fn (mut p Parser) parse_type() ast.Type {
|
||||
if is_option && sym.info is ast.SumType && sym.info.is_anon {
|
||||
p.error_with_pos('an inline sum type cannot be an Option', option_pos.extend(p.prev_tok.pos()))
|
||||
}
|
||||
|
||||
if is_option && sym.info is ast.Alias && sym.info.parent_type.has_flag(.option) {
|
||||
alias_type_str := p.table.type_to_str(typ)
|
||||
parent_type_str := p.table.type_to_str(sym.info.parent_type)
|
||||
p.error_with_pos('cannot use double options like `?${parent_type_str}`, `?${alias_type_str}` is a double option. use `${alias_type_str}` instead',
|
||||
option_pos.extend(p.prev_tok.pos()))
|
||||
}
|
||||
}
|
||||
if is_option {
|
||||
typ = typ.set_flag(.option)
|
||||
|
6
vlib/v/parser/tests/option_alias_option_type_err.out
Normal file
6
vlib/v/parser/tests/option_alias_option_type_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/parser/tests/option_alias_option_type_err.vv:4:11: error: cannot use double options like `??bool`, `?Foo` is a double option. use `Foo` instead
|
||||
2 |
|
||||
3 | struct Bar {
|
||||
4 | a ?Foo
|
||||
| ~~~~
|
||||
5 | }
|
5
vlib/v/parser/tests/option_alias_option_type_err.vv
Normal file
5
vlib/v/parser/tests/option_alias_option_type_err.vv
Normal file
@ -0,0 +1,5 @@
|
||||
type Foo = ?bool
|
||||
|
||||
struct Bar {
|
||||
a ?Foo
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user