From ad3835b5981c9b2ab633f088c9d9ad363142a270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Tue, 20 Jul 2021 10:17:08 +0200 Subject: [PATCH] parser: deprecate short struct init (#10842) --- cmd/tools/fast/fast.v | 2 +- cmd/tools/modules/testing/common.v | 2 +- cmd/tools/repeat.v | 4 +-- cmd/tools/vtest-all.v | 4 +-- cmd/tools/vtest-parser.v | 4 +-- doc/docs.md | 2 +- examples/2048/2048.v | 34 +++++++++---------- examples/fireworks/modules/objects/particle.v | 2 +- examples/fireworks/modules/objects/rocket.v | 6 ++-- examples/fireworks/modules/objects/vector.v | 2 +- examples/gg/worker_thread.v | 2 +- examples/sokol/sounds/simple_sin_tones.v | 2 +- examples/term.ui/rectangles.v | 4 +-- examples/term.ui/term_drawing.v | 6 ++-- examples/term.ui/text_editor.v | 4 +-- examples/term.ui/vyper.v | 4 +-- examples/tetris/tetris.v | 4 +-- vlib/benchmark/benchmark.v | 6 ++-- vlib/builtin/js/builtin.v | 4 +-- vlib/gg/text_rendering.v | 2 +- vlib/io/readerwriter.v | 2 +- vlib/io/util/util.v | 4 +-- vlib/io/util/util_test.v | 4 +-- vlib/net/address.v | 18 +++++----- vlib/net/tcp.v | 8 ++--- vlib/net/udp.v | 12 +++---- vlib/rand/dist/dist.v | 4 +-- vlib/rand/rand.v | 2 +- vlib/sync/bench/channel_bench_v.v | 2 +- .../many_writers_and_receivers_on_1_channel.v | 4 +-- vlib/sync/channel_select_3_test.v | 2 +- vlib/sync/channels.v | 2 +- vlib/time/stopwatch_test.v | 4 +-- vlib/v/ast/table.v | 2 +- vlib/v/builder/compile.v | 2 +- vlib/v/checker/checker.v | 2 +- .../checker/tests/array_or_map_assign_err.out | 12 +++---- .../checker/tests/array_or_map_assign_err.vv | 4 +-- .../tests/for_in_map_one_variable_err.out | 2 +- .../tests/for_in_map_one_variable_err.vv | 2 +- vlib/v/checker/tests/for_in_mut_val_type.out | 10 +++--- vlib/v/checker/tests/for_in_mut_val_type.vv | 4 +-- vlib/v/checker/tests/in_mismatch_type.vv | 2 +- vlib/v/checker/tests/map_delete.out | 4 +-- vlib/v/checker/tests/map_delete.vv | 6 ++-- .../tests/map_init_key_duplicate_err.out | 10 +++--- .../tests/map_init_key_duplicate_err.vv | 6 ++-- vlib/v/checker/tests/map_init_wrong_type.out | 32 ++++++++--------- vlib/v/checker/tests/map_init_wrong_type.vv | 6 ++-- .../tests/mut_map_get_value_address_err.out | 2 +- .../tests/mut_map_get_value_address_err.vv | 2 +- .../tests/no_interface_instantiation_b.out | 6 ++-- .../tests/no_interface_instantiation_b.vv | 2 +- vlib/v/checker/tests/shared_bad_args.vv | 4 +-- .../struct_assigned_to_pointer_to_struct.out | 13 ++----- .../struct_assigned_to_pointer_to_struct.vv | 1 - vlib/v/compiler_errors_test.v | 2 +- vlib/v/fmt/attrs.v | 2 +- vlib/v/fmt/comments.v | 4 +-- vlib/v/fmt/fmt.v | 26 +++++++------- vlib/v/fmt/struct.v | 2 +- .../tests/fn_trailing_arg_syntax_expected.vv | 2 +- .../fmt/tests/fn_trailing_arg_syntax_input.vv | 2 +- vlib/v/fmt/tests/select_keep.vv | 2 +- vlib/v/gen/c/cgen.v | 2 +- vlib/v/gen/js/sourcemap/mappings.v | 2 +- vlib/v/live/executable/reloader.v | 4 +-- vlib/v/parser/assign.v | 2 +- vlib/v/parser/containers.v | 10 +++--- vlib/v/parser/expr.v | 9 +++-- vlib/v/parser/fn.v | 4 +-- vlib/v/parser/if_match.v | 24 ++++++------- vlib/v/parser/parser.v | 14 ++++---- vlib/v/parser/struct.v | 21 ++++++------ vlib/v/parser/tests/anon_fn_return_type.out | 2 +- vlib/v/parser/tests/anon_fn_return_type.vv | 4 +-- vlib/v/parser/tests/for_in_mut_key_of_map.out | 2 +- vlib/v/parser/tests/for_in_mut_key_of_map.vv | 2 +- vlib/v/parser/tests/or_default_missing.vv | 2 +- vlib/v/tests/match_in_fn_call_test.v | 12 +++---- vlib/v/tests/semaphore_timed_test.v | 2 +- vlib/v/tests/struct_test.v | 2 +- vlib/v/token/position.v | 2 +- vlib/v/util/timers.v | 2 +- vlib/x/ttf/ttf.v | 2 +- 85 files changed, 234 insertions(+), 238 deletions(-) diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index 2a5a7cf483..3410de8771 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -122,7 +122,7 @@ fn measure(cmd string, description string) int { mut runs := []int{} for r in 0 .. 5 { println(' Sample ${r + 1}/5') - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() exec(cmd) runs << int(sw.elapsed().milliseconds()) } diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 57ff3e648e..2c4bfb2db1 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -70,7 +70,7 @@ pub fn (mut ts TestSession) append_message(kind MessageKind, msg string) { pub fn (mut ts TestSession) print_messages() { empty := term.header(' ', ' ') - mut print_msg_time := time.new_stopwatch({}) + mut print_msg_time := time.new_stopwatch() for { // get a message from the channel of messages to be printed: mut rmessage := <-ts.nmessages diff --git a/cmd/tools/repeat.v b/cmd/tools/repeat.v index 02c3c71171..6d65d190ec 100644 --- a/cmd/tools/repeat.v +++ b/cmd/tools/repeat.v @@ -245,7 +245,7 @@ fn (mut context Context) run() { if context.warmup > 0 && run_warmups < context.commands.len { for i in 1 .. context.warmup + 1 { print('${context.cgoback}warming up run: ${i:4}/${context.warmup:-4} for ${cmd:-50s} took ${duration:6} ms ...') - mut sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch() res := os.execute(cmd) if res.exit_code != 0 { continue @@ -261,7 +261,7 @@ fn (mut context Context) run() { if context.show_output { print(' | result: ${oldres:s}') } - mut sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch() res := scripting.exec(cmd) or { continue } duration = int(sw.elapsed().milliseconds()) if res.exit_code != 0 { diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index dd6a5bfe50..d865872d23 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -17,7 +17,7 @@ const vtest_nocleanup = os.getenv('VTEST_NOCLEANUP').bool() fn main() { mut commands := get_all_commands() // summary - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() for mut cmd in commands { cmd.run() } @@ -155,7 +155,7 @@ fn (mut cmd Command) run() { if cmd.label != '' { println(term.header_left(cmd.label, '*')) } - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() cmd.ecode = os.system(cmd.line) spent := sw.elapsed().milliseconds() println('> Running: "$cmd.line" took: $spent ms ... ' + diff --git a/cmd/tools/vtest-parser.v b/cmd/tools/vtest-parser.v index c021f10fbf..e1e829ae6f 100644 --- a/cmd/tools/vtest-parser.v +++ b/cmd/tools/vtest-parser.v @@ -73,9 +73,9 @@ fn main() { context.expand_all_paths() mut fails := 0 mut panics := 0 - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() for path in context.all_paths { - filesw := time.new_stopwatch({}) + filesw := time.new_stopwatch() context.start_printing() new_fails, new_panics := context.process_whole_file_in_worker(path) fails += new_fails diff --git a/doc/docs.md b/doc/docs.md index 826a89287a..1b0153ad12 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -4045,7 +4045,7 @@ You can also use stopwatches to measure just portions of your code explicitly: import time fn main() { - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() println('Hello world') println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns') } diff --git a/examples/2048/2048.v b/examples/2048/2048.v index 5e4871e101..d2372268ea 100644 --- a/examples/2048/2048.v +++ b/examples/2048/2048.v @@ -127,8 +127,8 @@ struct Perf { mut: frame int frame_old int - frame_sw time.StopWatch = time.new_stopwatch({}) - second_sw time.StopWatch = time.new_stopwatch({}) + frame_sw time.StopWatch = time.new_stopwatch() + second_sw time.StopWatch = time.new_stopwatch() } struct Pos { @@ -450,7 +450,7 @@ fn (p Prediction) str() string { fn (mut app App) ai_move() { mut predictions := [4]Prediction{} mut is_valid := false - think_watch := time.new_stopwatch({}) + think_watch := time.new_stopwatch() for move in possible_moves { move_idx := int(move) predictions[move_idx].move = move @@ -499,21 +499,21 @@ fn (mut app App) ai_move() { fn (app &App) label_format(kind LabelKind) gx.TextCfg { match kind { .points { - return { + return gx.TextCfg{ color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color } align: .left size: app.ui.font_size / 2 } } .moves { - return { + return gx.TextCfg{ color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color } align: .right size: app.ui.font_size / 2 } } .tile { - return { + return gx.TextCfg{ color: app.theme.text_color align: .center vertical_align: .middle @@ -521,7 +521,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg { } } .victory { - return { + return gx.TextCfg{ color: app.theme.victory_color align: .center vertical_align: .middle @@ -529,7 +529,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg { } } .game_over { - return { + return gx.TextCfg{ color: app.theme.game_over_color align: .center vertical_align: .middle @@ -537,7 +537,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg { } } .score_end { - return { + return gx.TextCfg{ color: gx.white align: .center vertical_align: .middle @@ -823,8 +823,8 @@ fn on_event(e &gg.Event, mut app App) { .touches_began { if e.num_touches > 0 { t := e.touches[0] - app.touch.start = { - pos: { + app.touch.start = Touch{ + pos: Pos{ x: int(t.pos_x / app.ui.dpi_scale) y: int(t.pos_y / app.ui.dpi_scale) } @@ -835,8 +835,8 @@ fn on_event(e &gg.Event, mut app App) { .touches_ended { if e.num_touches > 0 { t := e.touches[0] - app.touch.end = { - pos: { + app.touch.end = Touch{ + pos: Pos{ x: int(t.pos_x / app.ui.dpi_scale) y: int(t.pos_y / app.ui.dpi_scale) } @@ -846,8 +846,8 @@ fn on_event(e &gg.Event, mut app App) { } } .mouse_down { - app.touch.start = { - pos: { + app.touch.start = Touch{ + pos: Pos{ x: int(e.mouse_x / app.ui.dpi_scale) y: int(e.mouse_y / app.ui.dpi_scale) } @@ -855,8 +855,8 @@ fn on_event(e &gg.Event, mut app App) { } } .mouse_up { - app.touch.end = { - pos: { + app.touch.end = Touch{ + pos: Pos{ x: int(e.mouse_x / app.ui.dpi_scale) y: int(e.mouse_y / app.ui.dpi_scale) } diff --git a/examples/fireworks/modules/objects/particle.v b/examples/fireworks/modules/objects/particle.v index cd4004d550..8f84a394a9 100644 --- a/examples/fireworks/modules/objects/particle.v +++ b/examples/fireworks/modules/objects/particle.v @@ -32,5 +32,5 @@ pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) { particle.pos += particle.vel particle.draw(mut ctx) - particle.accel = {} + particle.accel = Vector{} } diff --git a/examples/fireworks/modules/objects/rocket.v b/examples/fireworks/modules/objects/rocket.v index 188c206822..ebdce0aa42 100644 --- a/examples/fireworks/modules/objects/rocket.v +++ b/examples/fireworks/modules/objects/rocket.v @@ -39,7 +39,7 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) { rocket.pos += rocket.vel rocket.draw(mut ctx) - rocket.accel = {} + rocket.accel = Vector{} } for mut particle in rocket.particles { @@ -50,10 +50,10 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) { pub fn new_rocket() Rocket { return Rocket{ color: random_color() - pos: { + pos: Vector{ x: rand.f32_in_range(50, get_params().width - 50) } - vel: { + vel: Vector{ x: rand.f32_in_range(-1.5, 1.5) y: rand.f32_in_range(5, 7) } diff --git a/examples/fireworks/modules/objects/vector.v b/examples/fireworks/modules/objects/vector.v index cfcd764740..0e29283fb7 100644 --- a/examples/fireworks/modules/objects/vector.v +++ b/examples/fireworks/modules/objects/vector.v @@ -21,7 +21,7 @@ pub fn random_vector_in_circle() Vector { theta := rand.f32n(2 * math.pi) y := rand.f32() - return { + return Vector{ x: f32(y * math.sin(theta)) y: f32(y * math.cos(theta)) } diff --git a/examples/gg/worker_thread.v b/examples/gg/worker_thread.v index b1bd454032..a2c9852ab8 100644 --- a/examples/gg/worker_thread.v +++ b/examples/gg/worker_thread.v @@ -48,7 +48,7 @@ fn init(mut app App) { // worker simulates a workload. This should be run in a separate thread. fn worker(mut app App) { - stopwatch := time.new_stopwatch({}) + stopwatch := time.new_stopwatch() mut elapsed := stopwatch.elapsed() // Do heavy operations here - like invoking a path finding algorithm, load an image or similar. for { diff --git a/examples/sokol/sounds/simple_sin_tones.v b/examples/sokol/sounds/simple_sin_tones.v index cf545142ac..c32711740d 100644 --- a/examples/sokol/sounds/simple_sin_tones.v +++ b/examples/sokol/sounds/simple_sin_tones.v @@ -3,7 +3,7 @@ import math import sokol.audio const ( - sw = time.new_stopwatch({}) + sw = time.new_stopwatch() sw_start_ms = sw.elapsed().milliseconds() ) diff --git a/examples/term.ui/rectangles.v b/examples/term.ui/rectangles.v index 9feb9649a9..09e9d6ad54 100644 --- a/examples/term.ui/rectangles.v +++ b/examples/term.ui/rectangles.v @@ -20,7 +20,7 @@ mut: } fn random_color() tui.Color { - return { + return tui.Color{ r: byte(rand.intn(256)) g: byte(rand.intn(256)) b: byte(rand.intn(256)) @@ -32,7 +32,7 @@ fn event(e &tui.Event, x voidptr) { match e.typ { .mouse_down { app.is_drag = true - app.cur_rect = { + app.cur_rect = Rect{ c: random_color() x: e.x y: e.y diff --git a/examples/term.ui/term_drawing.v b/examples/term.ui/term_drawing.v index 285cc87d90..df08cb78f0 100644 --- a/examples/term.ui/term_drawing.v +++ b/examples/term.ui/term_drawing.v @@ -156,20 +156,20 @@ fn event(event &ui.Event, x voidptr) { app.is_dragging = false } .mouse_drag { - app.mouse_pos = { + app.mouse_pos = Point{ x: event.x y: event.y } app.paint(event) } .mouse_move { - app.mouse_pos = { + app.mouse_pos = Point{ x: event.x y: event.y } } .mouse_scroll { - app.mouse_pos = { + app.mouse_pos = Point{ x: event.x y: event.y } diff --git a/examples/term.ui/text_editor.v b/examples/term.ui/text_editor.v index 11bf4b0a7a..78e6e40f1f 100644 --- a/examples/term.ui/text_editor.v +++ b/examples/term.ui/text_editor.v @@ -147,9 +147,9 @@ fn (b Buffer) view(from int, to int) View { } } raw := lines.join('\n') - return { + return View{ raw: raw.replace('\t', strings.repeat(` `, b.tab_width)) - cursor: { + cursor: Cursor{ pos_x: x pos_y: b.cursor.pos_y } diff --git a/examples/term.ui/vyper.v b/examples/term.ui/vyper.v index c5712c3b5d..cf41e605f8 100644 --- a/examples/term.ui/vyper.v +++ b/examples/term.ui/vyper.v @@ -60,7 +60,7 @@ fn (mut v Vec) randomize(min_x int, min_y int, max_x int, max_y int) { // part of snake's body representation struct BodyPart { mut: - pos Vec = { + pos Vec = Vec{ x: block_size y: block_size } @@ -241,7 +241,7 @@ fn (s Snake) draw() { // rat representation struct Rat { mut: - pos Vec = { + pos Vec = Vec{ x: block_size y: block_size } diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index 6b452932e5..01589a3670 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -119,8 +119,8 @@ mut: // frame/time counters: frame int frame_old int - frame_sw time.StopWatch = time.new_stopwatch({}) - second_sw time.StopWatch = time.new_stopwatch({}) + frame_sw time.StopWatch = time.new_stopwatch() + second_sw time.StopWatch = time.new_stopwatch() } fn remap(v f32, min f32, max f32, new_min f32, new_max f32) f32 { diff --git a/vlib/benchmark/benchmark.v b/vlib/benchmark/benchmark.v index ce8df9bd8b..cd9f9944c7 100644 --- a/vlib/benchmark/benchmark.v +++ b/vlib/benchmark/benchmark.v @@ -29,7 +29,7 @@ pub mut: // new_benchmark returns a `Benchmark` instance on the stack. pub fn new_benchmark() Benchmark { return Benchmark{ - bench_timer: time.new_stopwatch({}) + bench_timer: time.new_stopwatch() verbose: true } } @@ -37,7 +37,7 @@ pub fn new_benchmark() Benchmark { // new_benchmark_no_cstep returns a new `Benchmark` instance with step counting disabled. pub fn new_benchmark_no_cstep() Benchmark { return Benchmark{ - bench_timer: time.new_stopwatch({}) + bench_timer: time.new_stopwatch() verbose: true no_cstep: true } @@ -47,7 +47,7 @@ pub fn new_benchmark_no_cstep() Benchmark { // This is useful for long-lived use of `Benchmark` instances. pub fn new_benchmark_pointer() &Benchmark { return &Benchmark{ - bench_timer: time.new_stopwatch({}) + bench_timer: time.new_stopwatch() verbose: true } } diff --git a/vlib/builtin/js/builtin.v b/vlib/builtin/js/builtin.v index 9fe53ce564..86b60ad6e8 100644 --- a/vlib/builtin/js/builtin.v +++ b/vlib/builtin/js/builtin.v @@ -79,7 +79,7 @@ pub fn (o Option) str() string { pub fn error(s string) Option { return Option{ state: 2 - err: { + err: Error{ msg: s } } @@ -88,7 +88,7 @@ pub fn error(s string) Option { pub fn error_with_code(s string, code int) Option { return Option{ state: 2 - err: { + err: Error{ msg: s code: code } diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index 630b3bd446..dd0499d06e 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -193,7 +193,7 @@ pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) { } pub fn (ctx &Context) draw_text_def(x int, y int, text string) { - ctx.draw_text(x, y, text, {}) + ctx.draw_text(x, y, text) } /* diff --git a/vlib/io/readerwriter.v b/vlib/io/readerwriter.v index fccd51f1d9..ba44172ead 100644 --- a/vlib/io/readerwriter.v +++ b/vlib/io/readerwriter.v @@ -27,7 +27,7 @@ pub fn (mut r ReaderWriterImpl) write(buf []byte) ?int { // make_readerwriter takes a rstream and a wstream and makes // an rwstream with them pub fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl { - return { + return ReaderWriterImpl{ r: r w: w } diff --git a/vlib/io/util/util.v b/vlib/io/util/util.v index e27be3f3ee..6f0d93f516 100644 --- a/vlib/io/util/util.v +++ b/vlib/io/util/util.v @@ -24,7 +24,7 @@ pub fn temp_file(tfo TempFileOptions) ?(os.File, string) { ' could not create temporary file in "$d". Please ensure write permissions.') } d = d.trim_right(os.path_separator) - mut rng := rand.new_default({}) + mut rng := rand.new_default() prefix, suffix := prefix_and_suffix(tfo.pattern) or { return error(@FN + ' ' + err.msg) } for retry := 0; retry < util.retries; retry++ { path := os.join_path(d, prefix + random_number(mut rng) + suffix) @@ -60,7 +60,7 @@ pub fn temp_dir(tdo TempFileOptions) ?string { ' could not create temporary directory "$d". Please ensure write permissions.') } d = d.trim_right(os.path_separator) - mut rng := rand.new_default({}) + mut rng := rand.new_default() prefix, suffix := prefix_and_suffix(tdo.pattern) or { return error(@FN + ' ' + err.msg) } for retry := 0; retry < util.retries; retry++ { path := os.join_path(d, prefix + random_number(mut rng) + suffix) diff --git a/vlib/io/util/util_test.v b/vlib/io/util/util_test.v index 4cdf9dc2b0..1072cb58b8 100644 --- a/vlib/io/util/util_test.v +++ b/vlib/io/util/util_test.v @@ -26,7 +26,7 @@ fn testsuite_end() { fn test_temp_file() { // Test defaults - mut f, mut path := util.temp_file({}) or { + mut f, mut path := util.temp_file() or { assert false return } @@ -76,7 +76,7 @@ fn test_temp_file() { fn test_temp_dir() { // Test defaults - mut path := util.temp_dir({}) or { + mut path := util.temp_dir() or { assert false return } diff --git a/vlib/net/address.v b/vlib/net/address.v index ecc65c6fa8..af1a000caf 100644 --- a/vlib/net/address.v +++ b/vlib/net/address.v @@ -17,8 +17,8 @@ const ( fn new_ip6(port u16, addr [16]byte) Addr { a := Addr{ f: u16(AddrFamily.ip6) - addr: { - Ip6: { + addr: AddrData{ + Ip6: Ip6{ port: u16(C.htons(port)) } } @@ -32,8 +32,8 @@ fn new_ip6(port u16, addr [16]byte) Addr { fn new_ip(port u16, addr [4]byte) Addr { a := Addr{ f: u16(AddrFamily.ip) - addr: { - Ip: { + addr: AddrData{ + Ip: Ip{ port: u16(C.htons(port)) } } @@ -49,7 +49,7 @@ fn temp_unix() ?Addr { // close it // remove it // then reuse the filename - mut file, filename := util.temp_file({}) ? + mut file, filename := util.temp_file() ? file.close() os.rm(filename) ? addrs := resolve_addrs(filename, .unix, .udp) ? @@ -203,8 +203,8 @@ pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr { match AddrFamily(result.ai_family) { .ip, .ip6 { new_addr := Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } unsafe { @@ -246,8 +246,8 @@ fn (a Addr) str() string { pub fn addr_from_socket_handle(handle int) Addr { addr := Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } size := sizeof(addr) diff --git a/vlib/net/tcp.v b/vlib/net/tcp.v index a12b20273c..b7a34944ce 100644 --- a/vlib/net/tcp.v +++ b/vlib/net/tcp.v @@ -165,8 +165,8 @@ pub fn (mut c TcpConn) wait_for_write() ? { pub fn (c &TcpConn) peer_addr() ?Addr { mut addr := Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } mut size := sizeof(Addr) @@ -217,8 +217,8 @@ pub fn listen_tcp(family AddrFamily, saddr string) ?&TcpListener { pub fn (mut l TcpListener) accept() ?&TcpConn { addr := Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } size := sizeof(Addr) diff --git a/vlib/net/udp.v b/vlib/net/udp.v index 190393fd41..1df40037b4 100644 --- a/vlib/net/udp.v +++ b/vlib/net/udp.v @@ -104,8 +104,8 @@ pub fn (mut c UdpConn) write_to_string(addr Addr, s string) ?int { // read reads from the socket into buf up to buf.len returning the number of bytes read pub fn (mut c UdpConn) read(mut buf []byte) ?(int, Addr) { mut addr := Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } len := sizeof(Addr) @@ -206,8 +206,8 @@ fn new_udp_socket(local_addr Addr) ?&UdpSocket { handle: sockfd l: local_addr r: Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } } @@ -246,8 +246,8 @@ fn new_udp_socket_for_remote(raddr Addr) ?&UdpSocket { panic('Invalid family') // Appease compiler Addr{ - addr: { - Ip6: {} + addr: AddrData{ + Ip6: Ip6{} } } } diff --git a/vlib/rand/dist/dist.v b/vlib/rand/dist/dist.v index 5ebf256476..b2d905594d 100644 --- a/vlib/rand/dist/dist.v +++ b/vlib/rand/dist/dist.v @@ -40,7 +40,7 @@ pub struct NormalConfigStruct { // normal_pair returns a pair of normally distributed random numbers with the mean mu // and standard deviation sigma. If not specified, mu is 0 and sigma is 1. Intended usage is -// `x, y := normal_pair(mu: mean, sigma: stdev)`, or `x, y := normal_pair({})`. +// `x, y := normal_pair(mu: mean, sigma: stdev)`, or `x, y := normal_pair()`. pub fn normal_pair(config NormalConfigStruct) (f64, f64) { if config.sigma <= 0 { panic('The standard deviation has to be positive.') @@ -66,7 +66,7 @@ pub fn normal_pair(config NormalConfigStruct) (f64, f64) { // normal returns a normally distributed random number with the mean mu and standard deviation // sigma. If not specified, mu is 0 and sigma is 1. Intended usage is -// `x := normal(mu: mean, sigma: etdev)` or `x := normal({})`. +// `x := normal(mu: mean, sigma: etdev)` or `x := normal()`. // **NOTE:** If you are generating a lot of normal variates, use `the normal_pair` function // instead. This function discards one of the two variates generated by the `normal_pair` function. pub fn normal(config NormalConfigStruct) f64 { diff --git a/vlib/rand/rand.v b/vlib/rand/rand.v index ef832500da..0136ec1a96 100644 --- a/vlib/rand/rand.v +++ b/vlib/rand/rand.v @@ -49,7 +49,7 @@ __global ( // init initializes the default RNG. fn init() { - default_rng = new_default({}) + default_rng = new_default() } // new_default returns a new instance of the default RNG. If the seed is not provided, the current time will be used to seed the instance. diff --git a/vlib/sync/bench/channel_bench_v.v b/vlib/sync/bench/channel_bench_v.v index aa1189f739..54dcfe974b 100644 --- a/vlib/sync/bench/channel_bench_v.v +++ b/vlib/sync/bench/channel_bench_v.v @@ -32,7 +32,7 @@ fn main() { nrec := os.args[2].int() buflen := os.args[3].int() nobj := os.args[4].int() - stopwatch := time.new_stopwatch({}) + stopwatch := time.new_stopwatch() ch := chan int{cap: buflen} resch := chan i64{} mut no := nobj diff --git a/vlib/sync/bench/many_writers_and_receivers_on_1_channel.v b/vlib/sync/bench/many_writers_and_receivers_on_1_channel.v index d7db2b40de..999bb1dfa2 100644 --- a/vlib/sync/bench/many_writers_and_receivers_on_1_channel.v +++ b/vlib/sync/bench/many_writers_and_receivers_on_1_channel.v @@ -36,7 +36,7 @@ mut: fn do_rec(ch chan int, id int, mut ctx Context) { eprintln('start of do_rec id: $id') - mut timer_sw_x := time.new_stopwatch({}) + mut timer_sw_x := time.new_stopwatch() mut tmp := int(0) mut i := int(0) // NB: a single receiver thread can get slightly more @@ -69,7 +69,7 @@ fn do_rec(ch chan int, id int, mut ctx Context) { fn do_send(ch chan int, id int, mut ctx Context) { eprintln('start of do_send id: $id') - mut timer_sw_x := time.new_stopwatch({}) + mut timer_sw_x := time.new_stopwatch() n_iters := ctx.n_iters base := n_iters * id // sender events can not overlap for i := 0; i < n_iters; i++ { diff --git a/vlib/sync/channel_select_3_test.v b/vlib/sync/channel_select_3_test.v index 6a6c503e3d..9954ee3afe 100644 --- a/vlib/sync/channel_select_3_test.v +++ b/vlib/sync/channel_select_3_test.v @@ -86,7 +86,7 @@ fn test_select_blocks() { a: 13 } sem.wait() - stopwatch := time.new_stopwatch({}) + stopwatch := time.new_stopwatch() go f1(ch1, ch2, ch3, ch4, ch5, mut sem) sem.wait() elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond diff --git a/vlib/sync/channels.v b/vlib/sync/channels.v index 8acd6d326b..49f1396d49 100644 --- a/vlib/sync/channels.v +++ b/vlib/sync/channels.v @@ -648,7 +648,7 @@ pub fn channel_select(mut channels []&Channel, dir []Direction, mut objrefs []vo stopwatch := if timeout == time.infinite || timeout <= 0 { time.StopWatch{} } else { - time.new_stopwatch({}) + time.new_stopwatch() } mut event_idx := -1 // negative index means `timed out` diff --git a/vlib/time/stopwatch_test.v b/vlib/time/stopwatch_test.v index 16eadbabf3..49d005a556 100644 --- a/vlib/time/stopwatch_test.v +++ b/vlib/time/stopwatch_test.v @@ -4,7 +4,7 @@ import time // time than you have specified. To avoid false positives from CI test // failures, some of the asserts will be run only if you pass `-d stopwatch` fn test_stopwatch_works_as_intended() { - mut sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch() // sample code that you want to measure: println('Hello world') time.sleep(1 * time.millisecond) @@ -15,7 +15,7 @@ fn test_stopwatch_works_as_intended() { fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() { println('Testing pause function') - mut sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch() time.sleep(10 * time.millisecond) // A eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms') assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows.. diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 65f72fc2ba..71d1d4aec5 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -556,7 +556,7 @@ fn (mut t Table) check_for_already_registered_symbol(typ TypeSymbol, existing_id .placeholder { // override placeholder // println('overriding type placeholder `$typ.name`') - t.type_symbols[existing_idx] = { + t.type_symbols[existing_idx] = TypeSymbol{ ...typ methods: ex_type.methods } diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 29250aec71..22b3c9e9cc 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -37,7 +37,7 @@ pub fn compile(command string, pref &pref.Preferences) { println('builder.compile() pref:') // println(pref) } - mut sw := time.new_stopwatch({}) + mut sw := time.new_stopwatch() match pref.backend { .c { b.compile_c() } .js_node, .js_freestanding, .js_browser { b.compile_js() } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index afb5942236..b6b356c9a1 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1988,7 +1988,7 @@ pub fn (mut c Checker) check_expected_arg_count(mut call_expr ast.CallExpr, f &a last_sym := c.table.get_type_symbol(last_typ) if last_sym.kind == .struct_ { // allow empty trailing struct syntax arg (`f()` where `f` is `fn(ConfigStruct)`) - call_expr.args << { + call_expr.args << ast.CallArg{ expr: ast.StructInit{ typ: last_typ } diff --git a/vlib/v/checker/tests/array_or_map_assign_err.out b/vlib/v/checker/tests/array_or_map_assign_err.out index c1788de34e..fca758ba42 100644 --- a/vlib/v/checker/tests/array_or_map_assign_err.out +++ b/vlib/v/checker/tests/array_or_map_assign_err.out @@ -10,11 +10,11 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:5:5: error: use `array2 = array1 4 | mut a3 := []int{} 5 | a3 = a1 | ^ - 6 | - 7 | m1 := {'one': 1} + 6 | + 7 | m1 := map{'one': 1} vlib/v/checker/tests/array_or_map_assign_err.vv:8:8: error: cannot copy map: call `move` or `clone` method (or use a reference) - 6 | - 7 | m1 := {'one': 1} + 6 | + 7 | m1 := map{'one': 1} 8 | m2 := m1 | ~~ 9 | mut m3 := map[string]int{} @@ -24,10 +24,10 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:10:7: error: cannot copy map: ca 9 | mut m3 := map[string]int{} 10 | m3 = m1 | ~~ - 11 | + 11 | 12 | _ = a2 vlib/v/checker/tests/array_or_map_assign_err.vv:25:8: error: cannot copy map: call `move` or `clone` method (or use a reference) - 23 | + 23 | 24 | fn foo(mut m map[string]int) { 25 | m2 := m | ^ diff --git a/vlib/v/checker/tests/array_or_map_assign_err.vv b/vlib/v/checker/tests/array_or_map_assign_err.vv index f2463c8001..517a25d0b8 100644 --- a/vlib/v/checker/tests/array_or_map_assign_err.vv +++ b/vlib/v/checker/tests/array_or_map_assign_err.vv @@ -4,7 +4,7 @@ fn main() { mut a3 := []int{} a3 = a1 - m1 := {'one': 1} + m1 := map{'one': 1} m2 := m1 mut m3 := map[string]int{} m3 = m1 @@ -12,7 +12,7 @@ fn main() { _ = a2 _ = m2 - mut m := {'foo':1} + mut m := map{'foo':1} foo(mut m) _ = a3 diff --git a/vlib/v/checker/tests/for_in_map_one_variable_err.out b/vlib/v/checker/tests/for_in_map_one_variable_err.out index 48c26cce49..d7c6579ec2 100644 --- a/vlib/v/checker/tests/for_in_map_one_variable_err.out +++ b/vlib/v/checker/tests/for_in_map_one_variable_err.out @@ -1,7 +1,7 @@ vlib/v/checker/tests/for_in_map_one_variable_err.vv:3:6: error: declare a key and a value variable when ranging a map: `for key, val in map {` use `_` if you do not need the variable 1 | fn main() { - 2 | kvs := {'foo':'bar'} + 2 | kvs := map{'foo':'bar'} 3 | for k in kvs { | ^ 4 | println('$k') diff --git a/vlib/v/checker/tests/for_in_map_one_variable_err.vv b/vlib/v/checker/tests/for_in_map_one_variable_err.vv index 601c613df9..9297280ec7 100644 --- a/vlib/v/checker/tests/for_in_map_one_variable_err.vv +++ b/vlib/v/checker/tests/for_in_map_one_variable_err.vv @@ -1,5 +1,5 @@ fn main() { - kvs := {'foo':'bar'} + kvs := map{'foo':'bar'} for k in kvs { println('$k') } diff --git a/vlib/v/checker/tests/for_in_mut_val_type.out b/vlib/v/checker/tests/for_in_mut_val_type.out index 72ae690c45..d898cf75a4 100644 --- a/vlib/v/checker/tests/for_in_mut_val_type.out +++ b/vlib/v/checker/tests/for_in_mut_val_type.out @@ -14,7 +14,7 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:7:15: error: `a2` is immutable, it c 9 | } vlib/v/checker/tests/for_in_mut_val_type.vv:11:18: error: `m` is immutable, it cannot be changed 9 | } - 10 | m := {'aa': 1, 'bb': 2} + 10 | m := map{'aa': 1, 'bb': 2} 11 | for _, mut j in m { | ^ 12 | j *= 2 @@ -33,10 +33,10 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:17:15: error: array literal is immut | ~~~~~~~~~~ 18 | j *= 2 19 | } -vlib/v/checker/tests/for_in_mut_val_type.vv:20:18: error: map literal is immutable, it cannot be changed +vlib/v/checker/tests/for_in_mut_val_type.vv:20:21: error: map literal is immutable, it cannot be changed 18 | j *= 2 19 | } - 20 | for _, mut j in {'aa': 1, 'bb': 2} { - | ~~~~~~~~~~~~~~~~~~ + 20 | for _, mut j in map{'aa': 1, 'bb': 2} { + | ~~~~~~~~~~~~~~~~~~ 21 | j *= 2 - 22 | } + 22 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/for_in_mut_val_type.vv b/vlib/v/checker/tests/for_in_mut_val_type.vv index afd714bdf5..664fb66cf8 100644 --- a/vlib/v/checker/tests/for_in_mut_val_type.vv +++ b/vlib/v/checker/tests/for_in_mut_val_type.vv @@ -7,7 +7,7 @@ fn main() { for mut j in a2 { j *= 2 } - m := {'aa': 1, 'bb': 2} + m := map{'aa': 1, 'bb': 2} for _, mut j in m { j *= 2 } @@ -17,7 +17,7 @@ fn main() { for mut j in [1, 2, 3]! { j *= 2 } - for _, mut j in {'aa': 1, 'bb': 2} { + for _, mut j in map{'aa': 1, 'bb': 2} { j *= 2 } } diff --git a/vlib/v/checker/tests/in_mismatch_type.vv b/vlib/v/checker/tests/in_mismatch_type.vv index 2fc2bde89e..4a5dc697c3 100644 --- a/vlib/v/checker/tests/in_mismatch_type.vv +++ b/vlib/v/checker/tests/in_mismatch_type.vv @@ -3,7 +3,7 @@ type Int = int fn main() { a_i := [1, 2, 3] a_s := ['1', '2', '3'] - m := { + m := map{ 'test': 1 } s := 'abcd' diff --git a/vlib/v/checker/tests/map_delete.out b/vlib/v/checker/tests/map_delete.out index ecfbca0e21..c3a1822113 100644 --- a/vlib/v/checker/tests/map_delete.out +++ b/vlib/v/checker/tests/map_delete.out @@ -4,13 +4,13 @@ vlib/v/checker/tests/map_delete.vv:5:11: error: cannot use `int literal` as `str 5 | m.delete(1) | ^ 6 | m.delete(1, 2) - 7 | m2 := { + 7 | m2 := map{ vlib/v/checker/tests/map_delete.vv:6:4: error: expected 1 argument, but got 2 4 | } 5 | m.delete(1) 6 | m.delete(1, 2) | ~~~~~~~~~~~~ - 7 | m2 := { + 7 | m2 := map{ 8 | '1': 1 vlib/v/checker/tests/map_delete.vv:10:2: error: `m2` is immutable, declare it with `mut` to make it mutable 8 | '1': 1 diff --git a/vlib/v/checker/tests/map_delete.vv b/vlib/v/checker/tests/map_delete.vv index 0be6d170aa..26b26067c4 100644 --- a/vlib/v/checker/tests/map_delete.vv +++ b/vlib/v/checker/tests/map_delete.vv @@ -1,11 +1,11 @@ fn main() { - mut m := { + mut m := map{ '1': 1 } m.delete(1) m.delete(1, 2) - m2 := { + m2 := map{ '1': 1 } m2.delete('1') -} \ No newline at end of file +} diff --git a/vlib/v/checker/tests/map_init_key_duplicate_err.out b/vlib/v/checker/tests/map_init_key_duplicate_err.out index 5798002c82..d560b64116 100644 --- a/vlib/v/checker/tests/map_init_key_duplicate_err.out +++ b/vlib/v/checker/tests/map_init_key_duplicate_err.out @@ -5,9 +5,9 @@ vlib/v/checker/tests/map_init_key_duplicate_err.vv:5:3: error: duplicate key "fo | ~~~~~ 6 | } 7 | println(a) -vlib/v/checker/tests/map_init_key_duplicate_err.vv:9:15: error: duplicate key "2" in map literal +vlib/v/checker/tests/map_init_key_duplicate_err.vv:9:18: error: duplicate key "2" in map literal 7 | println(a) - 8 | - 9 | _ = {2:0 3:0 2:0} - | ^ - 10 | } + 8 | + 9 | _ = map{2:0 3:0 2:0} + | ^ + 10 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/map_init_key_duplicate_err.vv b/vlib/v/checker/tests/map_init_key_duplicate_err.vv index 952c003726..cd6efe6663 100644 --- a/vlib/v/checker/tests/map_init_key_duplicate_err.vv +++ b/vlib/v/checker/tests/map_init_key_duplicate_err.vv @@ -1,10 +1,10 @@ fn main() { - a := { + a := map{ 'foo': 'bar' 'abc': 'abc' 'foo': 'bar' } println(a) - - _ = {2:0 3:0 2:0} + + _ = map{2:0 3:0 2:0} } diff --git a/vlib/v/checker/tests/map_init_wrong_type.out b/vlib/v/checker/tests/map_init_wrong_type.out index 579f53ef28..117e787c9c 100644 --- a/vlib/v/checker/tests/map_init_wrong_type.out +++ b/vlib/v/checker/tests/map_init_wrong_type.out @@ -1,21 +1,21 @@ -vlib/v/checker/tests/map_init_wrong_type.vv:3:15: error: invalid map value: expected `f32`, not `float literal` +vlib/v/checker/tests/map_init_wrong_type.vv:3:18: error: invalid map value: expected `f32`, not `float literal` 1 | fn main() { 2 | mut a := map[string]f32{} - 3 | a = { 'x': 12.3 } - | ~~~~ - 4 | _ = {2:0 3:0 "hi":0} - 5 | _ = {2:0 3:`@` 4:0} -vlib/v/checker/tests/map_init_wrong_type.vv:4:17: error: invalid map key: expected `int`, not `string` + 3 | a = map{ 'x': 12.3 } + | ~~~~ + 4 | _ = map{2:0 3:0 "hi":0} + 5 | _ = map{2:0 3:`@` 4:0} +vlib/v/checker/tests/map_init_wrong_type.vv:4:20: error: invalid map key: expected `int`, not `string` 2 | mut a := map[string]f32{} - 3 | a = { 'x': 12.3 } - 4 | _ = {2:0 3:0 "hi":0} - | ~~~~ - 5 | _ = {2:0 3:`@` 4:0} + 3 | a = map{ 'x': 12.3 } + 4 | _ = map{2:0 3:0 "hi":0} + | ~~~~ + 5 | _ = map{2:0 3:`@` 4:0} 6 | _ = a -vlib/v/checker/tests/map_init_wrong_type.vv:5:15: error: invalid map value: expected `int`, not `rune` - 3 | a = { 'x': 12.3 } - 4 | _ = {2:0 3:0 "hi":0} - 5 | _ = {2:0 3:`@` 4:0} - | ~~~ +vlib/v/checker/tests/map_init_wrong_type.vv:5:18: error: invalid map value: expected `int`, not `rune` + 3 | a = map{ 'x': 12.3 } + 4 | _ = map{2:0 3:0 "hi":0} + 5 | _ = map{2:0 3:`@` 4:0} + | ~~~ 6 | _ = a - 7 | } + 7 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/map_init_wrong_type.vv b/vlib/v/checker/tests/map_init_wrong_type.vv index 56b7b960f3..dc41230625 100644 --- a/vlib/v/checker/tests/map_init_wrong_type.vv +++ b/vlib/v/checker/tests/map_init_wrong_type.vv @@ -1,7 +1,7 @@ fn main() { mut a := map[string]f32{} - a = { 'x': 12.3 } - _ = {2:0 3:0 "hi":0} - _ = {2:0 3:`@` 4:0} + a = map{ 'x': 12.3 } + _ = map{2:0 3:0 "hi":0} + _ = map{2:0 3:`@` 4:0} _ = a } diff --git a/vlib/v/checker/tests/mut_map_get_value_address_err.out b/vlib/v/checker/tests/mut_map_get_value_address_err.out index 0a8983ffa9..297c22825c 100644 --- a/vlib/v/checker/tests/mut_map_get_value_address_err.out +++ b/vlib/v/checker/tests/mut_map_get_value_address_err.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/mut_map_get_value_address_err.vv:3:12: error: cannot take the address of map values 1 | fn main() { - 2 | mut m := {'key' : 3} + 2 | mut m := map{'key' : 3} 3 | a := &m['key'] | ~~~~~~~ 4 | println(a) diff --git a/vlib/v/checker/tests/mut_map_get_value_address_err.vv b/vlib/v/checker/tests/mut_map_get_value_address_err.vv index 1f3cc58a9d..46e5b771af 100644 --- a/vlib/v/checker/tests/mut_map_get_value_address_err.vv +++ b/vlib/v/checker/tests/mut_map_get_value_address_err.vv @@ -1,5 +1,5 @@ fn main() { - mut m := {'key' : 3} + mut m := map{'key' : 3} a := &m['key'] println(a) } diff --git a/vlib/v/checker/tests/no_interface_instantiation_b.out b/vlib/v/checker/tests/no_interface_instantiation_b.out index 380417c64f..0a8f1b985e 100644 --- a/vlib/v/checker/tests/no_interface_instantiation_b.out +++ b/vlib/v/checker/tests/no_interface_instantiation_b.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/no_interface_instantiation_b.vv:6:12: error: cannot instantiate interface `Speaker` +vlib/v/checker/tests/no_interface_instantiation_b.vv:6:5: error: expected 1 arguments, but got 0 4 | 5 | fn main() { - 6 | my_fn({}) - | ^ + 6 | my_fn() + | ~~~~~~~ 7 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/no_interface_instantiation_b.vv b/vlib/v/checker/tests/no_interface_instantiation_b.vv index 01d47c8d10..4c73538868 100644 --- a/vlib/v/checker/tests/no_interface_instantiation_b.vv +++ b/vlib/v/checker/tests/no_interface_instantiation_b.vv @@ -3,5 +3,5 @@ interface Speaker {} fn my_fn(s Speaker) {} fn main() { - my_fn({}) + my_fn() } diff --git a/vlib/v/checker/tests/shared_bad_args.vv b/vlib/v/checker/tests/shared_bad_args.vv index 08e5d8a69b..f0d4913491 100644 --- a/vlib/v/checker/tests/shared_bad_args.vv +++ b/vlib/v/checker/tests/shared_bad_args.vv @@ -37,7 +37,7 @@ fn a_val(a []int) int { fn test_shared_as_value() { shared s := St{ a: 5 } shared a := [3, 4, 6, 13, -23] - shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} + shared m := map{'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} shared r := Qr{ a: 7 } lock s { u := r.s_val(s) @@ -55,7 +55,7 @@ fn test_shared_as_value() { fn test_shared_as_mut() { shared s := St{ a: 5 } shared a := [3, 4, 6, 13, -23] - shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} + shared m := map{'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} shared r := Qr{ a: 7 } lock s { r.s_mut(mut s) diff --git a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out index 666f29561d..54b047e060 100644 --- a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out +++ b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out @@ -1,14 +1,7 @@ vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:5:4: error: mismatched types `&Foo` and `Foo` 3 | fn main() { 4 | mut f := &Foo{ 10 } - 5 | f = { x: 223344 } + 5 | f = Foo{ x: 20 } | ^ - 6 | f = Foo{ x: 20 } - 7 | _ = f -vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:6:4: error: mismatched types `&Foo` and `Foo` - 4 | mut f := &Foo{ 10 } - 5 | f = { x: 223344 } - 6 | f = Foo{ x: 20 } - | ^ - 7 | _ = f - 8 | } + 6 | _ = f + 7 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv index f281856e92..5e963492f9 100644 --- a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv +++ b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv @@ -2,7 +2,6 @@ struct Foo { x int } fn main() { mut f := &Foo{ 10 } - f = { x: 223344 } f = Foo{ x: 20 } _ = f } diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 13c1c9ffae..0bb0effed4 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -271,7 +271,7 @@ fn work_processor(mut work sync.Channel, mut results sync.Channel) { if !work.pop(&task) { break } - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() task.execute() task.took = sw.elapsed() results.push(&task) diff --git a/vlib/v/fmt/attrs.v b/vlib/v/fmt/attrs.v index 4efafb872c..798cbb2d42 100644 --- a/vlib/v/fmt/attrs.v +++ b/vlib/v/fmt/attrs.v @@ -11,7 +11,7 @@ pub fn (mut f Fmt) attrs(attrs []ast.Attr) { sorted_attrs.sort(a.arg.len > b.arg.len) for i, attr in sorted_attrs { if attr.arg.len == 0 { - f.single_line_attrs(sorted_attrs[i..], {}) + f.single_line_attrs(sorted_attrs[i..]) break } f.writeln('[$attr]') diff --git a/vlib/v/fmt/comments.v b/vlib/v/fmt/comments.v index 580eccf3b4..8c557943fa 100644 --- a/vlib/v/fmt/comments.v +++ b/vlib/v/fmt/comments.v @@ -53,7 +53,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { out_s += s } if !is_separate_line && f.indent > 0 { - f.remove_new_line({}) // delete the generated \n + f.remove_new_line() // delete the generated \n f.write(' ') } f.write(out_s) @@ -73,7 +73,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { if end_break { f.empty_line = true } else { - f.remove_new_line({}) + f.remove_new_line() } f.write('*/') } diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index f9d98a1d52..c72a2ae721 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -267,7 +267,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) { already_imported[import_text] = true f.out_imports.writeln(import_text) f.import_comments(imp.comments, inline: true) - f.import_comments(imp.next_comments, {}) + f.import_comments(imp.next_comments) num_imports++ } if num_imports > 0 { @@ -855,7 +855,7 @@ pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) { } pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) { - f.comments(node.comments, {}) + f.comments(node.comments) for i, left in node.left { f.expr(left) if i < node.left.len - 1 { @@ -989,7 +989,7 @@ pub fn (mut f Fmt) defer_stmt(node ast.DeferStmt) { } pub fn (mut f Fmt) expr_stmt(node ast.ExprStmt) { - f.comments(node.comments, {}) + f.comments(node.comments) f.expr(node.expr) if !f.single_line_if { f.writeln('') @@ -1060,7 +1060,7 @@ pub fn (mut f Fmt) for_c_stmt(node ast.ForCStmt) { f.expr(node.cond) f.write('; ') f.stmt(node.inc) - f.remove_new_line({}) + f.remove_new_line() f.write(' {') if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line { f.writeln('') @@ -1240,7 +1240,7 @@ pub fn (mut f Fmt) mod(mod ast.Module) { } pub fn (mut f Fmt) return_stmt(node ast.Return) { - f.comments(node.comments, {}) + f.comments(node.comments) f.write('return') if node.exprs.len > 0 { f.write(' ') @@ -1643,7 +1643,7 @@ pub fn (mut f Fmt) at_expr(node ast.AtExpr) { pub fn (mut f Fmt) call_expr(node ast.CallExpr) { for arg in node.args { - f.comments(arg.comments, {}) + f.comments(arg.comments) } if node.is_method { if node.name in ['map', 'filter'] { @@ -1882,12 +1882,12 @@ pub fn (mut f Fmt) if_expr(node ast.IfExpr) { for i, branch in node.branches { if i == 0 { // first `if` - f.comments(branch.comments, {}) + f.comments(branch.comments) } else { // `else`, close previous branch if branch.comments.len > 0 { f.writeln('}') - f.comments(branch.comments, {}) + f.comments(branch.comments) } else { f.write('} ') } @@ -2070,7 +2070,7 @@ fn (mut f Fmt) write_splitted_infix(conditions []string, penalties []int, ignore continue } if i == 0 { - f.remove_new_line({}) + f.remove_new_line() } f.writeln('') f.indent++ @@ -2151,7 +2151,7 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) { } f.writeln('map{') f.indent++ - f.comments(node.pre_cmnts, {}) + f.comments(node.pre_cmnts) mut max_field_len := 0 for key in node.keys { if key.str().len > max_field_len { @@ -2177,7 +2177,7 @@ fn (mut f Fmt) match_branch(branch ast.MatchBranch, single_line bool) { for j, expr in branch.exprs { estr := f.node_str(expr).trim_space() if f.line_len + estr.len + 2 > fmt.max_len[5] { - f.remove_new_line({}) + f.remove_new_line() f.writeln('') } f.write(estr) @@ -2204,7 +2204,7 @@ fn (mut f Fmt) match_branch(branch ast.MatchBranch, single_line bool) { } f.stmts(branch.stmts) if single_line { - f.remove_new_line({}) + f.remove_new_line() f.writeln(' }') } else { f.writeln('}') @@ -2221,7 +2221,7 @@ pub fn (mut f Fmt) match_expr(node ast.MatchExpr) { } f.writeln(' {') f.indent++ - f.comments(node.comments, {}) + f.comments(node.comments) mut single_line := true for branch in node.branches { if branch.stmts.len > 1 || branch.pos.line_nr < branch.pos.last_line { diff --git a/vlib/v/fmt/struct.v b/vlib/v/fmt/struct.v index 0147051724..799c4279ac 100644 --- a/vlib/v/fmt/struct.v +++ b/vlib/v/fmt/struct.v @@ -354,7 +354,7 @@ pub fn (mut f Fmt) struct_init(node ast.StructInit) { single_line_fields = false f.out.go_back_to(fields_start) f.line_len = fields_start - f.remove_new_line({}) + f.remove_new_line() continue fields_loop } } diff --git a/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv b/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv index 83761672b3..255d5ca579 100644 --- a/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv +++ b/vlib/v/fmt/tests/fn_trailing_arg_syntax_expected.vv @@ -22,7 +22,7 @@ fn main() { y: 0 } ) - bar2_func({}, {}) + bar2_func({}) bar2_func({ x: 's' }, x: 's' ) diff --git a/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv b/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv index f1d48fe1e9..110161985a 100644 --- a/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv +++ b/vlib/v/fmt/tests/fn_trailing_arg_syntax_input.vv @@ -16,7 +16,7 @@ fn main() { x: 0 y: 0 }) - bar2_func({}, {}) + bar2_func({}) bar2_func({x: 's'}, {x: 's'}) baz_func('foo', 'bar', x: 0 y: 0 diff --git a/vlib/v/fmt/tests/select_keep.vv b/vlib/v/fmt/tests/select_keep.vv index 3b44fa4328..afc27c3d6f 100644 --- a/vlib/v/fmt/tests/select_keep.vv +++ b/vlib/v/fmt/tests/select_keep.vv @@ -89,7 +89,7 @@ fn test_select_blocks() { a: 13 } sem.wait() - stopwatch := time.new_stopwatch({}) + stopwatch := time.new_stopwatch() go f1(ch1, ch2, ch3, ch4, ch5, sem) sem.wait() elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index dd525ddbc0..45ada89f10 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6359,7 +6359,7 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype params_start_pos := g.out.len mut params := method.params.clone() // hack to mutate typ - params[0] = { + params[0] = ast.Param{ ...params[0] typ: params[0].typ.set_nr_muls(1) } diff --git a/vlib/v/gen/js/sourcemap/mappings.v b/vlib/v/gen/js/sourcemap/mappings.v index 7933845d98..d7aff132ca 100644 --- a/vlib/v/gen/js/sourcemap/mappings.v +++ b/vlib/v/gen/js/sourcemap/mappings.v @@ -42,7 +42,7 @@ mut: fn new_mappings() Mappings { return Mappings{ last: Mapping{ - GenPosition: { + GenPosition: GenPosition{ gen_column: 0 gen_line: 0 } diff --git a/vlib/v/live/executable/reloader.v b/vlib/v/live/executable/reloader.v index a4cad91ddd..960f543993 100644 --- a/vlib/v/live/executable/reloader.v +++ b/vlib/v/live/executable/reloader.v @@ -56,7 +56,7 @@ fn elog(r &live.LiveReloadInfo, s string) { } fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool { - sw := time.new_stopwatch({}) + sw := time.new_stopwatch() new_lib_path := compile_lib(mut r) or { return error('errors while compiling $r.original') } elog(r, '> compile_and_reload_shared_lib compiled: $new_lib_path') load_lib(mut r, new_lib_path) @@ -68,7 +68,7 @@ fn compile_lib(mut r live.LiveReloadInfo) ?string { new_lib_path, new_lib_path_with_extension := current_shared_library_path(mut r) cmd := '$r.vexe $r.vopts -o $new_lib_path $r.original' elog(r, '> compilation cmd: $cmd') - cwatch := time.new_stopwatch({}) + cwatch := time.new_stopwatch() recompilation_result := os.execute(cmd) elog(r, 'compilation took: ${cwatch.elapsed().milliseconds()}ms') if recompilation_result.exit_code != 0 { diff --git a/vlib/v/parser/assign.v b/vlib/v/parser/assign.v index 518dd18248..76c074ae05 100644 --- a/vlib/v/parser/assign.v +++ b/vlib/v/parser/assign.v @@ -128,7 +128,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme p.next() mut comments := []ast.Comment{cap: 2 * left_comments.len + 1} comments << left_comments - comments << p.eat_comments({}) + comments << p.eat_comments() mut right_comments := []ast.Comment{} mut right := []ast.Expr{cap: left.len} right, right_comments = p.expr_list() diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index d29f8cc63e..1b22ca854f 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -45,14 +45,14 @@ fn (mut p Parser) array_init() ast.ArrayInit { // [1,2,3] or [const]byte old_inside_array_lit := p.inside_array_lit p.inside_array_lit = true - pre_cmnts = p.eat_comments({}) + pre_cmnts = p.eat_comments() for i := 0; p.tok.kind !in [.rsbr, .eof]; i++ { exprs << p.expr(0) - ecmnts << p.eat_comments({}) + ecmnts << p.eat_comments() if p.tok.kind == .comma { p.next() } - ecmnts.last() << p.eat_comments({}) + ecmnts.last() << p.eat_comments() } p.inside_array_lit = old_inside_array_lit line_nr := p.tok.line_nr @@ -168,7 +168,7 @@ fn (mut p Parser) map_init() ast.MapInit { mut keys := []ast.Expr{} mut vals := []ast.Expr{} mut comments := [][]ast.Comment{} - pre_cmnts := p.eat_comments({}) + pre_cmnts := p.eat_comments() for p.tok.kind !in [.rcbr, .eof] { key := p.expr(0) keys << key @@ -178,7 +178,7 @@ fn (mut p Parser) map_init() ast.MapInit { if p.tok.kind == .comma { p.next() } - comments << p.eat_comments({}) + comments << p.eat_comments() } return ast.MapInit{ keys: keys diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index 01cfcb3037..fc10e37e66 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -23,7 +23,7 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr { is_stmt_ident := p.is_stmt_ident p.is_stmt_ident = false if !p.pref.is_fmt { - p.eat_comments({}) + p.eat_comments() } inside_array_lit := p.inside_array_lit p.inside_array_lit = false @@ -297,18 +297,23 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr { } } .lcbr { + // TODO: remove this when deprecation will be removed, vfmt should handle it for a while // Map `{"age": 20}` or `{ x | foo:bar, a:10 }` p.next() if p.tok.kind in [.chartoken, .number, .string] { - // TODO deprecate + p.warn_with_pos("deprecated map syntax, use syntax like `map{'age': 20}`", + p.prev_tok.position()) node = p.map_init() } else { // it should be a struct if p.tok.kind == .name && p.peek_tok.kind == .pipe { + // TODO: remove deprecated p.warn_with_pos('use e.g. `...struct_var` instead', p.peek_tok.position()) node = p.assoc() } else if (p.tok.kind == .name && p.peek_tok.kind == .colon) || p.tok.kind in [.rcbr, .comment, .ellipsis] { + p.warn_with_pos('short struct initalization is deprecated, use explicit struct name', + p.prev_tok.position()) node = p.struct_init(true) // short_syntax: true } else if p.tok.kind == .name { p.next() diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 3ecb0ca664..b97fa4f1df 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -124,7 +124,7 @@ pub fn (mut p Parser) call_args() []ast.CallArg { if is_mut { p.next() } - mut comments := p.eat_comments({}) + mut comments := p.eat_comments() arg_start_pos := p.tok.position() mut array_decompose := false if p.tok.kind == .ellipsis { @@ -149,7 +149,7 @@ pub fn (mut p Parser) call_args() []ast.CallArg { comments = []ast.Comment{} } pos := arg_start_pos.extend(p.prev_tok.position()) - comments << p.eat_comments({}) + comments << p.eat_comments() args << ast.CallArg{ is_mut: is_mut share: ast.sharetype_from_flags(is_shared, is_atomic) diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 059a6cf7f2..f1e0fe9893 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -33,9 +33,9 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr { p.tok.position() } if p.tok.kind == .key_else { - comments << p.eat_comments({}) + comments << p.eat_comments() p.check(.key_else) - comments << p.eat_comments({}) + comments << p.eat_comments() if p.tok.kind == .key_match { p.error('cannot use `match` with `if` statements') return ast.IfExpr{} @@ -78,7 +78,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr { p.error('cannot use `match` with `if` statements') return ast.IfExpr{} } - comments << p.eat_comments({}) + comments << p.eat_comments() mut cond := ast.empty_expr() mut is_guard := false // `if x := opt() {` @@ -90,9 +90,9 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr { if p.scope.known_var(var_name) { p.error_with_pos('redefinition of `$var_name`', var_pos) } - comments << p.eat_comments({}) + comments << p.eat_comments() p.check(.decl_assign) - comments << p.eat_comments({}) + comments << p.eat_comments() expr := p.expr(0) cond = ast.IfGuardExpr{ var_name: var_name @@ -110,7 +110,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr { cond = p.expr(0) p.comp_if_cond = false } - comments << p.eat_comments({}) + comments << p.eat_comments() end_pos := p.prev_tok.position() body_pos := p.tok.position() p.inside_if = false @@ -128,7 +128,7 @@ fn (mut p Parser) if_expr(is_comptime bool) ast.IfExpr { if is_guard { p.close_scope() } - comments = p.eat_comments({}) + comments = p.eat_comments() if is_comptime { if p.tok.kind == .key_else { p.error('use `\$else` instead of `else` in compile-time `if` branches') @@ -167,7 +167,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { if !no_lcbr { p.check(.lcbr) } - comments := p.eat_comments({}) // comments before the first branch + comments := p.eat_comments() // comments before the first branch mut branches := []ast.MatchBranch{} for p.tok.kind != .eof { branch_first_pos := p.tok.position() @@ -187,7 +187,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { for { // Sum type match parsed_type := p.parse_type() - ecmnts << p.eat_comments({}) + ecmnts << p.eat_comments() types << parsed_type exprs << ast.TypeNode{ typ: parsed_type @@ -204,7 +204,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { for { p.inside_match_case = true expr := p.expr(0) - ecmnts << p.eat_comments({}) + ecmnts << p.eat_comments() p.inside_match_case = false if p.tok.kind == .dotdot { p.error_with_pos('match only supports inclusive (`...`) ranges, not exclusive (`..`)', @@ -238,7 +238,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { p.inside_match_body = false pos := branch_first_pos.extend_with_last_line(branch_last_pos, p.prev_tok.line_nr) branch_pos := branch_first_pos.extend_with_last_line(p.tok.position(), p.tok.line_nr) - post_comments := p.eat_comments({}) + post_comments := p.eat_comments() branches << ast.MatchBranch{ exprs: exprs ecmnts: ecmnts @@ -408,7 +408,7 @@ fn (mut p Parser) select_expr() ast.SelectExpr { len: branch_last_pos.pos - branch_first_pos.pos + branch_last_pos.len col: branch_first_pos.col } - post_comments := p.eat_comments({}) + post_comments := p.eat_comments() pos.update_last_line(p.prev_tok.line_nr) if post_comments.len > 0 { pos.last_line = post_comments.last().pos.last_line diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index c204a55034..4928f25a17 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2830,7 +2830,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl { mut fields := []ast.ConstField{} mut comments := []ast.Comment{} for { - comments = p.eat_comments({}) + comments = p.eat_comments() if is_block && p.tok.kind == .eof { p.error('unexpected eof, expecting ´)´') return ast.ConstDecl{} @@ -2887,7 +2887,7 @@ fn (mut p Parser) return_stmt() ast.Return { first_pos := p.tok.position() p.next() // no return - mut comments := p.eat_comments({}) + mut comments := p.eat_comments() if p.tok.kind == .rcbr { return ast.Return{ comments: comments @@ -2926,7 +2926,7 @@ fn (mut p Parser) global_decl() ast.GlobalDecl { mut fields := []ast.GlobalField{} mut comments := []ast.Comment{} for { - comments = p.eat_comments({}) + comments = p.eat_comments() if is_block && p.tok.kind == .eof { p.error('unexpected eof, expecting ´)´') return ast.GlobalDecl{} @@ -3005,7 +3005,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl { } name := p.prepend_mod(enum_name) p.check(.lcbr) - enum_decl_comments := p.eat_comments({}) + enum_decl_comments := p.eat_comments() mut vals := []string{} // mut default_exprs := []ast.Expr{} mut fields := []ast.EnumField{} @@ -3027,7 +3027,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl { expr: expr has_expr: has_expr comments: p.eat_comments(same_line: true) - next_comments: p.eat_comments({}) + next_comments: p.eat_comments() } } p.top_level_statement_end() @@ -3132,7 +3132,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { mut type_end_pos := p.prev_tok.position() type_pos = type_pos.extend(type_end_pos) p.next() - sum_variants << { + sum_variants << ast.TypeNode{ typ: first_type pos: type_pos } @@ -3144,7 +3144,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { prev_tok := p.prev_tok type_end_pos = prev_tok.position() type_pos = type_pos.extend(type_end_pos) - sum_variants << { + sum_variants << ast.TypeNode{ typ: variant_type pos: type_pos } diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 40778e1376..0471ca25e6 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -154,7 +154,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { } else if p.tok.kind == .key_module { if module_pos != -1 { p.error('redefinition of `module` section') - return {} + return ast.StructDecl{} } p.next() p.check(.colon) @@ -181,7 +181,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { // struct embedding type_pos = p.tok.position() typ = p.parse_type() - ecomments := p.eat_comments({}) + ecomments := p.eat_comments() type_pos = type_pos.extend(p.prev_tok.position()) if !is_on_top { p.error_with_pos('struct embedding must be declared at the beginning of the struct body', @@ -223,7 +223,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { field_pos = field_start_pos.extend(type_pos) } // Comments after type (same line) - comments << p.eat_comments({}) + comments << p.eat_comments() if p.tok.kind == .lsbr { // attrs are stored in `p.attrs` p.attributes() @@ -241,7 +241,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { else {} } has_default_expr = true - comments << p.eat_comments({}) + comments << p.eat_comments() } ast_fields << ast.StructField{ name: field_name @@ -337,11 +337,10 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { if !short_syntax { p.check(.lcbr) } - pre_comments := p.eat_comments({}) + pre_comments := p.eat_comments() mut fields := []ast.StructInitField{} mut i := 0 no_keys := p.peek_tok.kind != .colon && p.tok.kind != .rcbr && p.tok.kind != .ellipsis // `Vec{a,b,c} - // p.warn(is_short_syntax.str()) saved_is_amp := p.is_amp p.is_amp = false mut update_expr := ast.empty_expr() @@ -391,7 +390,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { p.next() } comments << p.eat_comments(same_line: true) - nline_comments << p.eat_comments({}) + nline_comments << p.eat_comments() if !is_update_expr { fields << ast.StructInitField{ name: field_name @@ -448,7 +447,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { generic_types := p.parse_generic_type_list() // println('interface decl $interface_name') p.check(.lcbr) - pre_comments := p.eat_comments({}) + pre_comments := p.eat_comments() if modless_name in p.imported_symbols { p.error_with_pos('cannot register interface `$interface_name`, this type was already imported', name_pos) @@ -488,7 +487,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { iface_pos := p.tok.position() iface_name := p.tok.lit iface_type := p.parse_type() - comments := p.eat_comments({}) + comments := p.eat_comments() ifaces << ast.InterfaceEmbedding{ name: iface_name typ: iface_type @@ -503,7 +502,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { if p.tok.kind == .key_mut { if is_mut { p.error_with_pos('redefinition of `mut` section', p.tok.position()) - return {} + return ast.InterfaceDecl{} } p.next() p.check(.colon) @@ -554,7 +553,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { method.pos = method.pos.extend(method.return_type_pos) } mcomments := p.eat_comments(same_line: true) - mnext_comments := p.eat_comments({}) + mnext_comments := p.eat_comments() method.comments = mcomments method.next_comments = mnext_comments methods << method diff --git a/vlib/v/parser/tests/anon_fn_return_type.out b/vlib/v/parser/tests/anon_fn_return_type.out index c787e54752..fe42d51966 100644 --- a/vlib/v/parser/tests/anon_fn_return_type.out +++ b/vlib/v/parser/tests/anon_fn_return_type.out @@ -1,6 +1,6 @@ vlib/v/parser/tests/anon_fn_return_type.vv:7:22: error: expected return type, not string `hi` for anonymous function 5 | _ = fn (name string) flag.Flag - 6 | _ = fn (name string) flag.Flag {return {}} + 6 | _ = fn (name string) flag.Flag {return flag.Flag{}} 7 | _ = fn (name string) "hi" + name | ~~~~ 8 | diff --git a/vlib/v/parser/tests/anon_fn_return_type.vv b/vlib/v/parser/tests/anon_fn_return_type.vv index 028d76e14c..fc50fa06d2 100644 --- a/vlib/v/parser/tests/anon_fn_return_type.vv +++ b/vlib/v/parser/tests/anon_fn_return_type.vv @@ -1,8 +1,8 @@ import flag -_ = fn (name string) +_ = fn (name string) _ = fn (name string) {} _ = fn (name string) flag.Flag -_ = fn (name string) flag.Flag {return {}} +_ = fn (name string) flag.Flag {return flag.Flag{}} _ = fn (name string) "hi" + name diff --git a/vlib/v/parser/tests/for_in_mut_key_of_map.out b/vlib/v/parser/tests/for_in_mut_key_of_map.out index 7c159a0338..6737a534da 100644 --- a/vlib/v/parser/tests/for_in_mut_key_of_map.out +++ b/vlib/v/parser/tests/for_in_mut_key_of_map.out @@ -1,6 +1,6 @@ vlib/v/parser/tests/for_in_mut_key_of_map.vv:3:6: error: index of array or key of map cannot be mutated 1 | fn main() { - 2 | mut m := {'foo': 1, 'bar': 2} + 2 | mut m := map{'foo': 1, 'bar': 2} 3 | for mut k, _ in m { | ~~~ 4 | println(k) diff --git a/vlib/v/parser/tests/for_in_mut_key_of_map.vv b/vlib/v/parser/tests/for_in_mut_key_of_map.vv index 22a5acade0..c8a2296983 100644 --- a/vlib/v/parser/tests/for_in_mut_key_of_map.vv +++ b/vlib/v/parser/tests/for_in_mut_key_of_map.vv @@ -1,5 +1,5 @@ fn main() { - mut m := {'foo': 1, 'bar': 2} + mut m := map{'foo': 1, 'bar': 2} for mut k, _ in m { println(k) } diff --git a/vlib/v/parser/tests/or_default_missing.vv b/vlib/v/parser/tests/or_default_missing.vv index d89db0d72e..ad9fa62988 100644 --- a/vlib/v/parser/tests/or_default_missing.vv +++ b/vlib/v/parser/tests/or_default_missing.vv @@ -7,7 +7,7 @@ fn test_array_or() { } fn test_map_or() { - m := { + m := map{ 'as': 3 'qw': 4 'kl': 5 diff --git a/vlib/v/tests/match_in_fn_call_test.v b/vlib/v/tests/match_in_fn_call_test.v index 5b478381c3..6b5f6a360e 100644 --- a/vlib/v/tests/match_in_fn_call_test.v +++ b/vlib/v/tests/match_in_fn_call_test.v @@ -33,10 +33,10 @@ fn f_compiles2(d Data) []Data { } fn test_match_in_fn_call() { - println(f_doesnotcompile({})) - assert f_doesnotcompile({}) == []Data{} - println(f_compiles1({})) - assert f_compiles1({}) == []Data{} - println(f_compiles2({})) - assert f_compiles2({}) == []Data{} + println(f_doesnotcompile()) + assert f_doesnotcompile() == []Data{} + println(f_compiles1()) + assert f_compiles1() == []Data{} + println(f_compiles2()) + assert f_compiles2() == []Data{} } diff --git a/vlib/v/tests/semaphore_timed_test.v b/vlib/v/tests/semaphore_timed_test.v index 5cac420a4a..2307a67031 100644 --- a/vlib/v/tests/semaphore_timed_test.v +++ b/vlib/v/tests/semaphore_timed_test.v @@ -16,7 +16,7 @@ fn test_semaphore() { unsafe { abc[0]-- } } // wait for the 2 coroutines to finish using the semaphore - stopwatch := time.new_stopwatch({}) + stopwatch := time.new_stopwatch() mut elapsed := stopwatch.elapsed() if !sem.timed_wait(200 * time.millisecond) { // we should come here due to timeout diff --git a/vlib/v/tests/struct_test.v b/vlib/v/tests/struct_test.v index 1af0a0325a..94fb957b9c 100644 --- a/vlib/v/tests/struct_test.v +++ b/vlib/v/tests/struct_test.v @@ -274,7 +274,7 @@ fn test_struct_literal_args() { n: 10 def: 20 ) - foo_config(10, {}) + foo_config(10) foo_config(10, n: 40) foo_config(40, n: 30, def: 40) diff --git a/vlib/v/token/position.v b/vlib/v/token/position.v index fc99cfc0ef..71cbf602ed 100644 --- a/vlib/v/token/position.v +++ b/vlib/v/token/position.v @@ -26,7 +26,7 @@ pub fn (pos Position) extend(end Position) Position { } pub fn (pos Position) extend_with_last_line(end Position, last_line int) Position { - return { + return Position{ len: end.pos - pos.pos + end.len line_nr: pos.line_nr last_line: last_line - 1 diff --git a/vlib/v/util/timers.v b/vlib/v/util/timers.v index 725891c7dc..ed9211f454 100644 --- a/vlib/v/util/timers.v +++ b/vlib/v/util/timers.v @@ -48,7 +48,7 @@ pub fn timing_set_should_print(should_print bool) { } pub fn (mut t Timers) start(name string) { - mut sw := t.swatches[name] or { time.new_stopwatch({}) } + mut sw := t.swatches[name] or { time.new_stopwatch() } sw.start() t.swatches[name] = sw } diff --git a/vlib/x/ttf/ttf.v b/vlib/x/ttf/ttf.v index 8f700910e9..fefa544e93 100644 --- a/vlib/x/ttf/ttf.v +++ b/vlib/x/ttf/ttf.v @@ -616,7 +616,7 @@ fn (mut tf TTF_File) read_offset_tables() { mut i := 0 for i < num_tables { tag := tf.get_string(4) - tf.tables[tag] = { + tf.tables[tag] = Offset_Table{ checksum: tf.get_u32() offset: tf.get_u32() length: tf.get_u32()