mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow enum initalization (#17361)
This commit is contained in:
parent
79b2c34f97
commit
e9a3817aed
@ -142,7 +142,7 @@ fn (mut en EpollNotifier) close() ! {
|
||||
// event_mask_to_flag is a helper function that converts a bitmask
|
||||
// returned by epoll_wait to FdEventType
|
||||
fn event_mask_to_flag(mask u32) FdEventType {
|
||||
mut flags := FdEventType{}
|
||||
mut flags := FdEventType.read
|
||||
|
||||
if mask & notify.epoll_read != 0 {
|
||||
flags.set(.read)
|
||||
|
@ -174,7 +174,7 @@ fn (mut ctx Context) parse_events() {
|
||||
else { unsafe { KeyCode(ascii) } }
|
||||
}
|
||||
|
||||
mut modifiers := Modifiers{}
|
||||
mut modifiers := Modifiers.ctrl
|
||||
if e.dwControlKeyState & (0x1 | 0x2) != 0 {
|
||||
modifiers.set(.alt)
|
||||
}
|
||||
@ -204,7 +204,7 @@ fn (mut ctx Context) parse_events() {
|
||||
}
|
||||
x := e.dwMousePosition.X + 1
|
||||
y := int(e.dwMousePosition.Y) - sb_info.srWindow.Top + 1
|
||||
mut modifiers := Modifiers{}
|
||||
mut modifiers := Modifiers.ctrl
|
||||
if e.dwControlKeyState & (0x1 | 0x2) != 0 {
|
||||
modifiers.set(.alt)
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ fn escape_sequence(buf_ string) (&Event, int) {
|
||||
lo := typ & 0b00011
|
||||
hi := typ & 0b11100
|
||||
|
||||
mut modifiers := Modifiers{}
|
||||
mut modifiers := Modifiers.ctrl
|
||||
if hi & 4 != 0 {
|
||||
modifiers.set(.shift)
|
||||
}
|
||||
@ -503,7 +503,7 @@ fn escape_sequence(buf_ string) (&Event, int) {
|
||||
// ----------------------------
|
||||
|
||||
mut code := KeyCode.null
|
||||
mut modifiers := Modifiers{}
|
||||
mut modifiers := Modifiers.ctrl
|
||||
match buf {
|
||||
'[A', 'OA' { code = .up }
|
||||
'[B', 'OB' { code = .down }
|
||||
|
@ -360,6 +360,9 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
|
||||
&& type_sym.kind != .placeholder {
|
||||
c.error('cannot initialize builtin type `${type_sym.name}`', node.pos)
|
||||
}
|
||||
if type_sym.kind == .enum_ && !c.pref.translated && !c.file.is_translated {
|
||||
c.error('cannot initialize enums', node.pos)
|
||||
}
|
||||
}
|
||||
if type_sym.kind == .sum_type && node.fields.len == 1 {
|
||||
sexpr := node.fields[0].expr.str()
|
||||
|
7
vlib/v/checker/tests/enum_init_err.out
Normal file
7
vlib/v/checker/tests/enum_init_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/enum_init_err.vv:8:7: error: cannot initialize enums
|
||||
6 |
|
||||
7 | fn main() {
|
||||
8 | a := Hello{}
|
||||
| ~~~~~~~
|
||||
9 | println(a)
|
||||
10 | }
|
10
vlib/v/checker/tests/enum_init_err.vv
Normal file
10
vlib/v/checker/tests/enum_init_err.vv
Normal file
@ -0,0 +1,10 @@
|
||||
enum Hello {
|
||||
aaa
|
||||
bbb
|
||||
ccc
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := Hello{}
|
||||
println(a)
|
||||
}
|
@ -26,7 +26,7 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) {
|
||||
}
|
||||
mut remove_tail_zeros := false
|
||||
fspec := node.fmts[i]
|
||||
mut fmt_type := StrIntpType{}
|
||||
mut fmt_type := StrIntpType.si_no_str
|
||||
g.write('/*${fspec} ${sym}*/')
|
||||
// upper cases
|
||||
if (fspec - `A`) <= (`Z` - `A`) {
|
||||
|
@ -142,7 +142,7 @@ enum FileType {
|
||||
}
|
||||
|
||||
fn test_enum_instance() {
|
||||
mut filetype := FileType{}
|
||||
mut filetype := FileType.unknown
|
||||
eprintln(filetype)
|
||||
s := 'x ${filetype} z'
|
||||
assert s == 'x unknown z'
|
||||
|
Loading…
Reference in New Issue
Block a user