diff --git a/vlib/os/notify/backend_linux.c.v b/vlib/os/notify/backend_linux.c.v index e4875e658a..7c29016e58 100644 --- a/vlib/os/notify/backend_linux.c.v +++ b/vlib/os/notify/backend_linux.c.v @@ -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) diff --git a/vlib/term/ui/input_windows.c.v b/vlib/term/ui/input_windows.c.v index b2fe2dfc2f..6972f2308f 100644 --- a/vlib/term/ui/input_windows.c.v +++ b/vlib/term/ui/input_windows.c.v @@ -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) } diff --git a/vlib/term/ui/termios_nix.c.v b/vlib/term/ui/termios_nix.c.v index 7421d62cfe..ee64a79420 100644 --- a/vlib/term/ui/termios_nix.c.v +++ b/vlib/term/ui/termios_nix.c.v @@ -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 } diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index d6bb3fc83b..ad73a2713b 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -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() diff --git a/vlib/v/checker/tests/enum_init_err.out b/vlib/v/checker/tests/enum_init_err.out new file mode 100644 index 0000000000..de805c447a --- /dev/null +++ b/vlib/v/checker/tests/enum_init_err.out @@ -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 | } diff --git a/vlib/v/checker/tests/enum_init_err.vv b/vlib/v/checker/tests/enum_init_err.vv new file mode 100644 index 0000000000..bc73dd39b1 --- /dev/null +++ b/vlib/v/checker/tests/enum_init_err.vv @@ -0,0 +1,10 @@ +enum Hello { + aaa + bbb + ccc +} + +fn main() { + a := Hello{} + println(a) +} diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index 77415f3d8f..73f0ac1a58 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -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`) { diff --git a/vlib/v/tests/enum_test.v b/vlib/v/tests/enum_test.v index af4a1bd639..ace75c5bd8 100644 --- a/vlib/v/tests/enum_test.v +++ b/vlib/v/tests/enum_test.v @@ -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'