From 8b962f84462c5d9154fbf311f6f6e5574accfff1 Mon Sep 17 00:00:00 2001 From: shove Date: Thu, 15 Sep 2022 12:59:31 +0800 Subject: [PATCH] checker: fix nested struct reference type field initialized check. (fix: #15741) (#15752) --- cmd/tools/gen_vc.v | 4 +-- cmd/tools/vast/vast.v | 4 +-- cmd/tools/vtest-parser.v | 2 +- cmd/tools/vwatch.v | 2 +- examples/2048/2048.v | 4 +-- examples/clock/clock.v | 2 +- examples/fireworks/fireworks.v | 4 +-- examples/flappylearning/game.v | 2 +- examples/game_of_life/life_gg.v | 2 +- .../modules/automaton/automaton.v | 4 +-- examples/gg/bezier.v | 2 +- examples/gg/bezier_anim.v | 4 +-- examples/gg/drag_n_drop.v | 4 +-- examples/gg/draw_pixels.v | 2 +- examples/gg/mandelbrot.v | 2 +- examples/gg/random.v | 2 +- examples/gg/raven_text_rendering.v | 2 +- examples/gg/rectangles.v | 2 +- examples/gg/stars.v | 2 +- examples/gg/worker_thread.v | 2 +- examples/hot_reload/bounce.v | 2 +- examples/hot_reload/graph.v | 2 +- examples/macos_tray/tray.v | 2 +- examples/path_tracing.v | 2 +- .../modules/sim/anim/app.v | 2 +- examples/snek/snek.js.v | 2 +- examples/snek/snek.v | 2 +- examples/sokol/01_cubes/cube.v | 2 +- examples/sokol/02_cubes_glsl/cube_glsl.v | 2 +- .../sokol/03_march_tracing_glsl/rt_glsl.v | 2 +- examples/sokol/04_multi_shader_glsl/rt_glsl.v | 2 +- examples/sokol/05_instancing_glsl/rt_glsl.v | 2 +- .../sokol/06_obj_viewer/modules/obj/struct.v | 4 +-- examples/sokol/06_obj_viewer/show_obj.v | 2 +- examples/sokol/freetype_raven.v | 2 +- examples/sokol/sounds/melody.v | 2 +- examples/term.ui/cursor_chaser.v | 2 +- examples/term.ui/event_viewer.v | 2 +- examples/term.ui/pong.v | 8 ++--- examples/term.ui/rectangles.v | 2 +- examples/term.ui/term_drawing.v | 2 +- examples/term.ui/text_editor.v | 4 +-- examples/term.ui/vyper.v | 6 ++-- examples/ttf_font/example_ttf.v | 2 +- examples/viewer/view.v | 8 ++--- vlib/builtin/builtin_windows.c.v | 8 ++--- vlib/builtin/map.v | 6 ++-- vlib/cli/command.v | 2 +- vlib/clipboard/clipboard_windows.c.v | 6 ++-- vlib/clipboard/x11/clipboard.c.v | 2 +- vlib/dlmalloc/dlmalloc.v | 6 ++-- vlib/eventbus/eventbus.v | 10 +++--- vlib/fontstash/fontstash_structs.c.v | 2 +- vlib/gg/gg.c.v | 2 +- vlib/gg/testdata/draw_simple_polygons.vv | 2 +- vlib/gg/text_rendering.c.v | 2 +- vlib/mysql/result.v | 2 +- vlib/net/ftp/ftp.v | 4 +-- vlib/net/html/dom.v | 2 +- vlib/net/html/parser.v | 2 +- vlib/net/html/tag.v | 2 +- vlib/net/openssl/ssl_connection.v | 4 +-- vlib/net/smtp/smtp.v | 2 +- vlib/net/urllib/urllib.v | 4 +-- vlib/net/websocket/websocket_client.v | 6 ++-- vlib/net/websocket/websocket_server.v | 8 ++--- vlib/os/os_android_outside_termux.c.v | 2 +- vlib/os/os_windows.c.v | 14 ++++---- vlib/os/process_windows.c.v | 10 +++--- vlib/pg/pg.v | 2 +- vlib/picoev/picoev.v | 8 ++--- vlib/picohttpparser/response.v | 6 ++-- vlib/sokol/sapp/screenshot.c.v | 2 +- vlib/sqlite/sqlite.v | 6 ++-- vlib/sync/channels.c.v | 14 ++++---- vlib/toml/checker/checker.v | 2 +- vlib/toml/decoder/decoder.v | 2 +- vlib/toml/parser/parser.v | 4 +-- vlib/toml/toml.v | 2 +- vlib/v/ast/ast.v | 32 +++++++++---------- vlib/v/ast/scope.v | 2 +- vlib/v/ast/table.v | 4 +-- vlib/v/builder/builder.v | 8 ++--- vlib/v/callgraph/callgraph.v | 10 +++--- vlib/v/checker/checker.v | 6 ++-- vlib/v/checker/struct.v | 31 ++++++++++++++++++ .../reference_field_must_be_initialized.out | 9 +++++- .../tests/struct_field_reference_type_err.out | 9 +++++- .../struct_ref_fields_uninitialized_err.out | 7 ++++ .../struct_ref_fields_uninitialized_err.vv | 13 ++++++++ vlib/v/embed_file/embed_file.v | 6 ++-- vlib/v/eval/eval.v | 2 +- vlib/v/eval/object.v | 2 +- vlib/v/fmt/fmt.v | 4 +-- vlib/v/gen/c/cgen.v | 14 ++++---- vlib/v/gen/golang/golang.v | 4 +-- vlib/v/gen/js/js.v | 14 ++++---- vlib/v/gen/js/jsdoc.v | 2 +- vlib/v/gen/js/util.v | 4 +-- vlib/v/gen/native/amd64.v | 2 +- vlib/v/gen/native/arm64.v | 2 +- vlib/v/gen/native/gen.v | 6 ++-- vlib/v/markused/walker.v | 4 +-- vlib/v/parser/parser.v | 14 ++++---- vlib/v/pkgconfig/main.v | 2 +- vlib/v/transformer/transformer.v | 2 +- vlib/vweb/sse/sse.v | 2 +- vlib/vweb/vweb.v | 2 +- vlib/x/json2/decoder.v | 2 +- vlib/x/ttf/render_bmp.v | 4 +-- vlib/x/ttf/render_sokol_cpu.v | 2 +- 111 files changed, 287 insertions(+), 222 deletions(-) create mode 100644 vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out create mode 100644 vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv diff --git a/cmd/tools/gen_vc.v b/cmd/tools/gen_vc.v index 3430d218f..7428bb433 100644 --- a/cmd/tools/gen_vc.v +++ b/cmd/tools/gen_vc.v @@ -82,7 +82,7 @@ struct GenVC { // flag options options FlagOptions mut: - logger &log.Log + logger &log.Log = unsafe { nil } // true if error was experienced running generate gen_error bool } @@ -91,7 +91,7 @@ mut: struct WebhookServer { vweb.Context mut: - gen_vc &GenVC = unsafe { 0 } // initialized in init_server + gen_vc &GenVC = unsafe { nil } // initialized in init_server } // storage for flag options diff --git a/cmd/tools/vast/vast.v b/cmd/tools/vast/vast.v index 05a9eba27..0a5e168e5 100644 --- a/cmd/tools/vast/vast.v +++ b/cmd/tools/vast/vast.v @@ -140,8 +140,8 @@ fn json(file string) string { // the ast tree struct Tree { - table &ast.Table - pref &pref.Preferences + table &ast.Table = unsafe { nil } + pref &pref.Preferences = unsafe { nil } mut: root Node // the root of tree } diff --git a/cmd/tools/vtest-parser.v b/cmd/tools/vtest-parser.v index 33e50e384..bde3a5fd5 100644 --- a/cmd/tools/vtest-parser.v +++ b/cmd/tools/vtest-parser.v @@ -35,7 +35,7 @@ mut: // parser context in the worker processes: table ast.Table scope ast.Scope - pref &pref.Preferences + pref &pref.Preferences = unsafe { nil } period_ms int // print periodic progress stop_print bool // stop printing the periodic progress } diff --git a/cmd/tools/vwatch.v b/cmd/tools/vwatch.v index 518394ccb..a20f646b7 100644 --- a/cmd/tools/vwatch.v +++ b/cmd/tools/vwatch.v @@ -84,7 +84,7 @@ mut: vfiles []VFileStat opts []string rerun_channel chan RerunCommand - child_process &os.Process + child_process &os.Process = unsafe { nil } is_exiting bool // set by SIGINT/Ctrl-C v_cycles int // how many times the worker has restarted the V compiler scan_cycles int // how many times the worker has scanned for source file changes diff --git a/examples/2048/2048.v b/examples/2048/2048.v index e71994e17..2d505ac4e 100644 --- a/examples/2048/2048.v +++ b/examples/2048/2048.v @@ -7,7 +7,7 @@ import time struct App { mut: - gg &gg.Context = unsafe { 0 } + gg &gg.Context = unsafe { nil } touch TouchInfo ui Ui theme &Theme = themes[0] @@ -18,7 +18,7 @@ mut: state GameState = .play tile_format TileFormat = .normal moves int - perf &Perf = unsafe { 0 } + perf &Perf = unsafe { nil } is_ai_mode bool } diff --git a/examples/clock/clock.v b/examples/clock/clock.v index ce52be964..da8f6ba1a 100644 --- a/examples/clock/clock.v +++ b/examples/clock/clock.v @@ -42,7 +42,7 @@ struct App { minute_hand []f32 = [f32(334.25), 40.25, 350, 24.5, 365.75, 40.25, 365.75, 427, 334.25, 427] second_hand []f32 = [f32(345.8), 38.5, 350, 34.3, 354.2000, 38.5, 358.75, 427, 341.25, 427] mut: - gg &gg.Context = unsafe { 0 } + gg &gg.Context = unsafe { nil } draw_flag bool = true dpi_scale f32 = 1.0 } diff --git a/examples/fireworks/fireworks.v b/examples/fireworks/fireworks.v index 212e94069..cff2bf434 100644 --- a/examples/fireworks/fireworks.v +++ b/examples/fireworks/fireworks.v @@ -6,8 +6,8 @@ import rand struct App { mut: - gg &gg.Context = unsafe { 0 } - ui &objects.UIParams = unsafe { 0 } + gg &gg.Context = unsafe { nil } + ui &objects.UIParams = unsafe { nil } rockets []objects.Rocket frames [][]objects.Rocket // i thought about using a fixed fifo queue for the frames but the array diff --git a/examples/flappylearning/game.v b/examples/flappylearning/game.v index 628c25609..5643b8e1d 100644 --- a/examples/flappylearning/game.v +++ b/examples/flappylearning/game.v @@ -66,7 +66,7 @@ fn (p Pipe) is_out() bool { struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } background gg.Image bird gg.Image pipetop gg.Image diff --git a/examples/game_of_life/life_gg.v b/examples/game_of_life/life_gg.v index 9eaaecfde..d7b28155d 100644 --- a/examples/game_of_life/life_gg.v +++ b/examples/game_of_life/life_gg.v @@ -26,7 +26,7 @@ fn print_automaton(app &App) { struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } a automaton.Automaton } diff --git a/examples/game_of_life/modules/automaton/automaton.v b/examples/game_of_life/modules/automaton/automaton.v index e68d64bf9..92fe3bd9d 100644 --- a/examples/game_of_life/modules/automaton/automaton.v +++ b/examples/game_of_life/modules/automaton/automaton.v @@ -48,8 +48,8 @@ pub fn (a &A2D) clear() { // /////////////////////////////////////////////////////////// pub struct Automaton { pub mut: - field &A2D - new_field &A2D + field &A2D = unsafe { nil } + new_field &A2D = unsafe { nil } } fn new_automaton(ftext string) Automaton { diff --git a/examples/gg/bezier.v b/examples/gg/bezier.v index e5cb6751b..e0bebf4ec 100644 --- a/examples/gg/bezier.v +++ b/examples/gg/bezier.v @@ -9,7 +9,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } } fn main() { diff --git a/examples/gg/bezier_anim.v b/examples/gg/bezier_anim.v index 2f54ac946..c02b19869 100644 --- a/examples/gg/bezier_anim.v +++ b/examples/gg/bezier_anim.v @@ -7,8 +7,8 @@ const rate = f32(1) / 60 * 10 struct App { mut: - gg &gg.Context - anim &Anim + gg &gg.Context = unsafe { nil } + anim &Anim = unsafe { nil } } struct Anim { diff --git a/examples/gg/drag_n_drop.v b/examples/gg/drag_n_drop.v index 2529ca075..608703569 100644 --- a/examples/gg/drag_n_drop.v +++ b/examples/gg/drag_n_drop.v @@ -13,8 +13,8 @@ const ( struct App { mut: - gg &gg.Context - dropped_file_list []string = []string{} + gg &gg.Context = unsafe { nil } + dropped_file_list []string = []string{} } fn main() { diff --git a/examples/gg/draw_pixels.v b/examples/gg/draw_pixels.v index 769086662..c49bf1dfa 100644 --- a/examples/gg/draw_pixels.v +++ b/examples/gg/draw_pixels.v @@ -5,7 +5,7 @@ import gx struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } pixels []f32 } diff --git a/examples/gg/mandelbrot.v b/examples/gg/mandelbrot.v index 6384afa69..a9d0ed4b9 100644 --- a/examples/gg/mandelbrot.v +++ b/examples/gg/mandelbrot.v @@ -31,7 +31,7 @@ fn (v &ViewRect) height() f64 { struct AppState { mut: - gg &gg.Context = unsafe { 0 } + gg &gg.Context = unsafe { nil } iidx int pixels &u32 = unsafe { vcalloc(pwidth * pheight * sizeof(u32)) } npixels &u32 = unsafe { vcalloc(pwidth * pheight * sizeof(u32)) } // all drawing happens here, results are swapped at the end diff --git a/examples/gg/random.v b/examples/gg/random.v index ecd0b989b..b90b1da9e 100644 --- a/examples/gg/random.v +++ b/examples/gg/random.v @@ -9,7 +9,7 @@ const pbytes = 4 struct AppState { mut: - gg &gg.Context = unsafe { 0 } + gg &gg.Context = unsafe { nil } istream_idx int pixels [pheight][pwidth]u32 } diff --git a/examples/gg/raven_text_rendering.v b/examples/gg/raven_text_rendering.v index 9318b969a..4c9477d58 100644 --- a/examples/gg/raven_text_rendering.v +++ b/examples/gg/raven_text_rendering.v @@ -60,7 +60,7 @@ Let my heart be still a moment and this mystery explore;— struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } } fn main() { diff --git a/examples/gg/rectangles.v b/examples/gg/rectangles.v index 400735ce7..d60c766af 100644 --- a/examples/gg/rectangles.v +++ b/examples/gg/rectangles.v @@ -11,7 +11,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } image gg.Image } diff --git a/examples/gg/stars.v b/examples/gg/stars.v index 7dca5c05e..cde572834 100644 --- a/examples/gg/stars.v +++ b/examples/gg/stars.v @@ -37,7 +37,7 @@ mut: struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } image gg.Image stars []Star v_letters []VLetter diff --git a/examples/gg/worker_thread.v b/examples/gg/worker_thread.v index 04d0f175a..285b3f6e9 100644 --- a/examples/gg/worker_thread.v +++ b/examples/gg/worker_thread.v @@ -18,7 +18,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } ch chan i64 counter i64 } diff --git a/examples/hot_reload/bounce.v b/examples/hot_reload/bounce.v index ece66cc91..14ff96ecb 100644 --- a/examples/hot_reload/bounce.v +++ b/examples/hot_reload/bounce.v @@ -8,7 +8,7 @@ import time struct Game { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } x int y int dy int diff --git a/examples/hot_reload/graph.v b/examples/hot_reload/graph.v index 907320aa7..ab417081b 100644 --- a/examples/hot_reload/graph.v +++ b/examples/hot_reload/graph.v @@ -12,7 +12,7 @@ const ( struct Context { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } } fn main() { diff --git a/examples/macos_tray/tray.v b/examples/macos_tray/tray.v index 261baddb6..e1fd99d32 100644 --- a/examples/macos_tray/tray.v +++ b/examples/macos_tray/tray.v @@ -35,7 +35,7 @@ struct TrayInfo { [heap] struct MyApp { mut: - tray_info &TrayInfo + tray_info &TrayInfo = unsafe { nil } } fn (app &MyApp) on_menu_item_click(item TrayMenuItem) { diff --git a/examples/path_tracing.v b/examples/path_tracing.v index 4cfe2ba3c..2d52cd4c3 100644 --- a/examples/path_tracing.v +++ b/examples/path_tracing.v @@ -84,7 +84,7 @@ fn (v Vec) norm() Vec { struct Image { width int height int - data &Vec + data &Vec = unsafe { nil } } fn new_image(w int, h int) Image { diff --git a/examples/pendulum-simulation/modules/sim/anim/app.v b/examples/pendulum-simulation/modules/sim/anim/app.v index ee1283503..9c9fda7bb 100644 --- a/examples/pendulum-simulation/modules/sim/anim/app.v +++ b/examples/pendulum-simulation/modules/sim/anim/app.v @@ -19,7 +19,7 @@ pub: request_chan chan &sim.SimRequest result_chan chan &sim.SimResult pub mut: - gg &gg.Context = unsafe { 0 } + gg &gg.Context = unsafe { nil } iidx int pixels []u32 } diff --git a/examples/snek/snek.js.v b/examples/snek/snek.js.v index b6f8e3f4e..0f64aca12 100644 --- a/examples/snek/snek.js.v +++ b/examples/snek/snek.js.v @@ -36,7 +36,7 @@ enum Direction { struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } score int snake []Pos dir Direction diff --git a/examples/snek/snek.v b/examples/snek/snek.v index f4a944173..367ecdb13 100644 --- a/examples/snek/snek.v +++ b/examples/snek/snek.v @@ -50,7 +50,7 @@ fn (mut h HighScore) load() { struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } score int best HighScore snake []Pos diff --git a/examples/sokol/01_cubes/cube.v b/examples/sokol/01_cubes/cube.v index 2ccfef9a3..6137d2b7f 100644 --- a/examples/sokol/01_cubes/cube.v +++ b/examples/sokol/01_cubes/cube.v @@ -25,7 +25,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } pip_3d sgl.Pipeline texture gfx.Image init_flag bool diff --git a/examples/sokol/02_cubes_glsl/cube_glsl.v b/examples/sokol/02_cubes_glsl/cube_glsl.v index 4cd677d58..7b863f079 100644 --- a/examples/sokol/02_cubes_glsl/cube_glsl.v +++ b/examples/sokol/02_cubes_glsl/cube_glsl.v @@ -36,7 +36,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } pip_3d sgl.Pipeline texture gfx.Image init_flag bool diff --git a/examples/sokol/03_march_tracing_glsl/rt_glsl.v b/examples/sokol/03_march_tracing_glsl/rt_glsl.v index a85ec6ac2..640288686 100644 --- a/examples/sokol/03_march_tracing_glsl/rt_glsl.v +++ b/examples/sokol/03_march_tracing_glsl/rt_glsl.v @@ -37,7 +37,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } texture gfx.Image init_flag bool frame_count int diff --git a/examples/sokol/04_multi_shader_glsl/rt_glsl.v b/examples/sokol/04_multi_shader_glsl/rt_glsl.v index 4a0113d89..fd817e7b8 100644 --- a/examples/sokol/04_multi_shader_glsl/rt_glsl.v +++ b/examples/sokol/04_multi_shader_glsl/rt_glsl.v @@ -37,7 +37,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } texture gfx.Image init_flag bool frame_count int diff --git a/examples/sokol/05_instancing_glsl/rt_glsl.v b/examples/sokol/05_instancing_glsl/rt_glsl.v index 12b52e15b..2cab6627f 100644 --- a/examples/sokol/05_instancing_glsl/rt_glsl.v +++ b/examples/sokol/05_instancing_glsl/rt_glsl.v @@ -32,7 +32,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } texture gfx.Image init_flag bool frame_count int diff --git a/examples/sokol/06_obj_viewer/modules/obj/struct.v b/examples/sokol/06_obj_viewer/modules/obj/struct.v index 5ddcb5089..da50da8f9 100644 --- a/examples/sokol/06_obj_viewer/modules/obj/struct.v +++ b/examples/sokol/06_obj_viewer/modules/obj/struct.v @@ -98,8 +98,8 @@ pub mut: // shader data for the rendering pub struct Shader_data { pub mut: - vs_data &Tmp_vs_param + vs_data &Tmp_vs_param = unsafe { nil } vs_len int - fs_data &Tmp_fs_param + fs_data &Tmp_fs_param = unsafe { nil } fs_len int } diff --git a/examples/sokol/06_obj_viewer/show_obj.v b/examples/sokol/06_obj_viewer/show_obj.v index 7d018a246..3b0253c75 100644 --- a/examples/sokol/06_obj_viewer/show_obj.v +++ b/examples/sokol/06_obj_viewer/show_obj.v @@ -45,7 +45,7 @@ const ( struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } texture gfx.Image init_flag bool frame_count int diff --git a/examples/sokol/freetype_raven.v b/examples/sokol/freetype_raven.v index a5c7c1fc7..2d72511a1 100644 --- a/examples/sokol/freetype_raven.v +++ b/examples/sokol/freetype_raven.v @@ -56,7 +56,7 @@ Let my heart be still a moment and this mystery explore;— struct AppState { mut: pass_action gfx.PassAction - fons &fontstash.Context + fons &fontstash.Context = unsafe { nil } font_normal int inited bool } diff --git a/examples/sokol/sounds/melody.v b/examples/sokol/sounds/melody.v index 9eb6c4a52..d4e582f91 100644 --- a/examples/sokol/sounds/melody.v +++ b/examples/sokol/sounds/melody.v @@ -9,7 +9,7 @@ mut: gframe int // the current graphical frame frame_0 int // offset of the current audio frames, relative to the start of the music frames [2048]f32 // a copy of the last rendered audio frames - gg &gg.Context // used for drawing + gg &gg.Context = unsafe { nil } // used for drawing } fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut acontext AppState) { diff --git a/examples/term.ui/cursor_chaser.v b/examples/term.ui/cursor_chaser.v index ba350cca6..affb702ef 100644 --- a/examples/term.ui/cursor_chaser.v +++ b/examples/term.ui/cursor_chaser.v @@ -18,7 +18,7 @@ struct Point { struct App { mut: - tui &tui.Context = unsafe { 0 } + tui &tui.Context = unsafe { nil } points []Point color tui.Color = colors[0] color_idx int diff --git a/examples/term.ui/event_viewer.v b/examples/term.ui/event_viewer.v index d7608fead..28a900c86 100644 --- a/examples/term.ui/event_viewer.v +++ b/examples/term.ui/event_viewer.v @@ -2,7 +2,7 @@ import term.ui as tui struct App { mut: - tui &tui.Context = unsafe { 0 } + tui &tui.Context = unsafe { nil } } fn event(e &tui.Event, x voidptr) { diff --git a/examples/term.ui/pong.v b/examples/term.ui/pong.v index 8423d8f8c..cf576ddb4 100644 --- a/examples/term.ui/pong.v +++ b/examples/term.ui/pong.v @@ -19,11 +19,11 @@ const ( [heap] struct App { mut: - tui &ui.Context = unsafe { 0 } + tui &ui.Context = unsafe { nil } mode Mode = Mode.menu width int height int - game &Game = unsafe { 0 } + game &Game = unsafe { nil } dt f32 ticks i64 } @@ -191,7 +191,7 @@ fn (mut a App) draw_game() { struct Player { mut: - game &Game + game &Game = unsafe { nil } pos Vec racket_size int = 4 score int @@ -242,7 +242,7 @@ fn (mut b Ball) update(dt f32) { [heap] struct Game { mut: - app &App = unsafe { 0 } + app &App = unsafe { nil } players []Player ball Ball } diff --git a/examples/term.ui/rectangles.v b/examples/term.ui/rectangles.v index 63c4757f4..97da3b4bf 100644 --- a/examples/term.ui/rectangles.v +++ b/examples/term.ui/rectangles.v @@ -12,7 +12,7 @@ mut: struct App { mut: - tui &tui.Context = unsafe { 0 } + tui &tui.Context = unsafe { nil } rects []Rect cur_rect Rect is_drag bool diff --git a/examples/term.ui/term_drawing.v b/examples/term.ui/term_drawing.v index aff91a015..c4d31c57b 100644 --- a/examples/term.ui/term_drawing.v +++ b/examples/term.ui/term_drawing.v @@ -90,7 +90,7 @@ const ( struct App { mut: - ui &ui.Context = unsafe { 0 } + ui &ui.Context = unsafe { nil } header_text []string mouse_pos Point msg string diff --git a/examples/term.ui/text_editor.v b/examples/term.ui/text_editor.v index 50cb14093..db243bfe4 100644 --- a/examples/term.ui/text_editor.v +++ b/examples/term.ui/text_editor.v @@ -57,8 +57,8 @@ pub: struct App { mut: - tui &tui.Context = unsafe { 0 } - ed &Buffer = unsafe { 0 } + tui &tui.Context = unsafe { nil } + ed &Buffer = unsafe { nil } current_file int files []string status string diff --git a/examples/term.ui/vyper.v b/examples/term.ui/vyper.v index 4f09554a2..0cf8ab3da 100644 --- a/examples/term.ui/vyper.v +++ b/examples/term.ui/vyper.v @@ -71,7 +71,7 @@ mut: // snake representation struct Snake { mut: - app &App + app &App = unsafe { nil } direction Orientation body []BodyPart velocity Vec = Vec{ @@ -247,7 +247,7 @@ mut: } captured bool color termui.Color = grey - app &App + app &App = unsafe { nil } } // randomize spawn the rat in a new spot within the playable field @@ -259,7 +259,7 @@ fn (mut r Rat) randomize() { [heap] struct App { mut: - termui &termui.Context = unsafe { 0 } + termui &termui.Context = unsafe { nil } snake Snake rat Rat width int diff --git a/examples/ttf_font/example_ttf.v b/examples/ttf_font/example_ttf.v index 2edb417f2..144257582 100644 --- a/examples/ttf_font/example_ttf.v +++ b/examples/ttf_font/example_ttf.v @@ -20,7 +20,7 @@ const ( // UI struct App_data { pub mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } sg_img gfx.Image init_flag bool frame_c int diff --git a/examples/viewer/view.v b/examples/viewer/view.v index d031b4230..07b50f213 100644 --- a/examples/viewer/view.v +++ b/examples/viewer/view.v @@ -60,7 +60,7 @@ enum Viewer_state { struct App { mut: - gg &gg.Context + gg &gg.Context = unsafe { nil } pip_viewer sgl.Pipeline texture gfx.Image init_flag bool @@ -88,13 +88,13 @@ mut: img_h int img_ratio f32 = 1.0 // item list - item_list &Item_list + item_list &Item_list = unsafe { nil } // Text info and help show_info_flag bool = true show_help_flag bool // zip container - zip &szip.Zip // pointer to the szip structure - zip_index int = -1 // index of the zip contaire item + zip &szip.Zip = unsafe { nil } // pointer to the szip structure + zip_index int = -1 // index of the zip contaire item // memory buffer mem_buf voidptr // buffer used to load items from files/containers mem_buf_size int // size of the buffer diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index 6cd91c046..8b1d7ef21 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -37,7 +37,7 @@ pub mut: f_size_of_struct u32 f_key voidptr f_line_number u32 - f_file_name &u8 + f_file_name &u8 = unsafe { nil } f_address u64 } @@ -214,7 +214,7 @@ pub: // status_ constants code u32 flags u32 - record &ExceptionRecord + record &ExceptionRecord = unsafe { nil } address voidptr param_count u32 // params []voidptr @@ -226,8 +226,8 @@ struct ContextRecord { struct ExceptionPointers { pub: - exception_record &ExceptionRecord - context_record &ContextRecord + exception_record &ExceptionRecord = unsafe { nil } + context_record &ContextRecord = unsafe { nil } } type VectoredExceptionHandler = fn (&ExceptionPointers) int diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index a102623cd..7fb9ab651 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -85,9 +85,9 @@ mut: deletes u32 // count // array allocated (with `cap` bytes) on first deletion // has non-zero element when key deleted - all_deleted &u8 - keys &u8 - values &u8 + all_deleted &u8 = unsafe { nil } + keys &u8 = unsafe { nil } + values &u8 = unsafe { nil } } [inline] diff --git a/vlib/cli/command.v b/vlib/cli/command.v index 217d0f6ca..b88e9c570 100644 --- a/vlib/cli/command.v +++ b/vlib/cli/command.v @@ -27,7 +27,7 @@ pub mut: disable_flags bool sort_flags bool sort_commands bool - parent &Command = unsafe { 0 } + parent &Command = unsafe { nil } commands []Command flags []Flag required_args int diff --git a/vlib/clipboard/clipboard_windows.c.v b/vlib/clipboard/clipboard_windows.c.v index d15d8aa34..8f22b27a8 100644 --- a/vlib/clipboard/clipboard_windows.c.v +++ b/vlib/clipboard/clipboard_windows.c.v @@ -15,9 +15,9 @@ struct WndClassEx { h_icon C.HICON h_cursor C.HCURSOR hbr_background C.HBRUSH - lpsz_menu_name &u16 // LPCWSTR - lpsz_class_name &u16 - h_icon_sm &u16 + lpsz_menu_name &u16 = unsafe { nil } // LPCWSTR + lpsz_class_name &u16 = unsafe { nil } + h_icon_sm &u16 = unsafe { nil } } fn C.RegisterClassEx(class &WndClassEx) int diff --git a/vlib/clipboard/x11/clipboard.c.v b/vlib/clipboard/x11/clipboard.c.v index df996a2a7..f38f4fce7 100644 --- a/vlib/clipboard/x11/clipboard.c.v +++ b/vlib/clipboard/x11/clipboard.c.v @@ -155,7 +155,7 @@ struct Property { actual_type Atom actual_format int nitems u64 - data &u8 + data &u8 = unsafe { nil } } // new_clipboard returns a new `Clipboard` instance allocated on the heap. diff --git a/vlib/dlmalloc/dlmalloc.v b/vlib/dlmalloc/dlmalloc.v index 202fafa93..4ec5e204a 100644 --- a/vlib/dlmalloc/dlmalloc.v +++ b/vlib/dlmalloc/dlmalloc.v @@ -265,8 +265,8 @@ struct Chunk { mut: prev_foot usize head usize - prev &Chunk - next &Chunk + prev &Chunk = unsafe { nil } + next &Chunk = unsafe { nil } } [heap] @@ -274,7 +274,7 @@ struct Segment { mut: base voidptr size usize - next &Segment + next &Segment = unsafe { nil } flags u32 } diff --git a/vlib/eventbus/eventbus.v b/vlib/eventbus/eventbus.v index 15af78ac2..f85cf792d 100644 --- a/vlib/eventbus/eventbus.v +++ b/vlib/eventbus/eventbus.v @@ -4,12 +4,12 @@ pub type EventHandlerFn = fn (receiver voidptr, args voidptr, sender voidptr) pub struct Publisher { mut: - registry &Registry + registry &Registry = unsafe { nil } } pub struct Subscriber { mut: - registry &Registry + registry &Registry = unsafe { nil } } struct Registry { @@ -26,9 +26,9 @@ struct EventHandler { pub struct EventBus { pub mut: - registry &Registry - publisher &Publisher - subscriber &Subscriber + registry &Registry = unsafe { nil } + publisher &Publisher = unsafe { nil } + subscriber &Subscriber = unsafe { nil } } pub fn new() &EventBus { diff --git a/vlib/fontstash/fontstash_structs.c.v b/vlib/fontstash/fontstash_structs.c.v index 605404581..324db5464 100644 --- a/vlib/fontstash/fontstash_structs.c.v +++ b/vlib/fontstash/fontstash_structs.c.v @@ -38,7 +38,7 @@ pub struct C.FONStextIter { codepoint u32 isize i16 iblur i16 - font &C.FONSfont + font &C.FONSfont = unsafe { nil } prevGlyphIndex int str &u8 next &u8 diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 808ca36fe..380283c20 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -123,7 +123,7 @@ pub mut: timage_pip sgl.Pipeline config Config user_data voidptr - ft &FT + ft &FT = unsafe { nil } font_inited bool ui_mode bool // do not redraw everything 60 times/second, but only when the user requests frame u64 // the current frame counted from the start of the application; always increasing diff --git a/vlib/gg/testdata/draw_simple_polygons.vv b/vlib/gg/testdata/draw_simple_polygons.vv index 5a60fed4b..9493eba18 100644 --- a/vlib/gg/testdata/draw_simple_polygons.vv +++ b/vlib/gg/testdata/draw_simple_polygons.vv @@ -5,7 +5,7 @@ import gx struct App { mut: - gg &gg.Context = unsafe { 0 } + gg &gg.Context = unsafe { nil } rotation f32 = f32(0) edge int = 3 } diff --git a/vlib/gg/text_rendering.c.v b/vlib/gg/text_rendering.c.v index 3b724a89f..798057fa0 100644 --- a/vlib/gg/text_rendering.c.v +++ b/vlib/gg/text_rendering.c.v @@ -11,7 +11,7 @@ import os.font struct FT { pub: - fons &fontstash.Context + fons &fontstash.Context = unsafe { nil } font_normal int font_bold int font_mono int diff --git a/vlib/mysql/result.v b/vlib/mysql/result.v index 1070ed241..c1e7abb8e 100644 --- a/vlib/mysql/result.v +++ b/vlib/mysql/result.v @@ -1,7 +1,7 @@ module mysql pub struct Result { - result &C.MYSQL_RES + result &C.MYSQL_RES = unsafe { nil } } pub struct Row { diff --git a/vlib/net/ftp/ftp.v b/vlib/net/ftp/ftp.v index c6c1c0631..f6fc40f5a 100644 --- a/vlib/net/ftp/ftp.v +++ b/vlib/net/ftp/ftp.v @@ -36,7 +36,7 @@ const ( struct DTP { mut: - conn &net.TcpConn + conn &net.TcpConn = unsafe { nil } reader io.BufferedReader ip string port int @@ -61,7 +61,7 @@ fn (mut dtp DTP) close() { struct FTP { mut: - conn &net.TcpConn + conn &net.TcpConn = unsafe { nil } reader io.BufferedReader buffer_size int } diff --git a/vlib/net/html/dom.v b/vlib/net/html/dom.v index 839f28f87..6c4444a98 100644 --- a/vlib/net/html/dom.v +++ b/vlib/net/html/dom.v @@ -9,7 +9,7 @@ import os // https://www.w3.org/TR/WD-DOM/introduction.html pub struct DocumentObjectModel { mut: - root &Tag + root &Tag = unsafe { nil } constructed bool btree BTree all_tags []&Tag diff --git a/vlib/net/html/parser.v b/vlib/net/html/parser.v index 0da92c797..350af8917 100644 --- a/vlib/net/html/parser.v +++ b/vlib/net/html/parser.v @@ -5,7 +5,7 @@ import strings struct LexicalAttributes { mut: - current_tag &Tag + current_tag &Tag = unsafe { nil } open_tag bool open_code bool open_string int diff --git a/vlib/net/html/tag.v b/vlib/net/html/tag.v index c66cde03c..c704cce3b 100644 --- a/vlib/net/html/tag.v +++ b/vlib/net/html/tag.v @@ -16,7 +16,7 @@ pub mut: children []&Tag attributes map[string]string // attributes will be like map[name]value last_attribute string - parent &Tag = unsafe { 0 } + parent &Tag = unsafe { nil } position_in_parent int closed bool close_type CloseTagType = .in_name diff --git a/vlib/net/openssl/ssl_connection.v b/vlib/net/openssl/ssl_connection.v index 78737bfd0..a4e1a8de2 100644 --- a/vlib/net/openssl/ssl_connection.v +++ b/vlib/net/openssl/ssl_connection.v @@ -6,8 +6,8 @@ import time // SSLConn is the current connection pub struct SSLConn { mut: - sslctx &C.SSL_CTX - ssl &C.SSL + sslctx &C.SSL_CTX = unsafe { nil } + ssl &C.SSL = unsafe { nil } handle int duration time.Duration } diff --git a/vlib/net/smtp/smtp.v b/vlib/net/smtp/smtp.v index 57f1ab68b..b9240c02c 100644 --- a/vlib/net/smtp/smtp.v +++ b/vlib/net/smtp/smtp.v @@ -32,7 +32,7 @@ pub enum BodyType { pub struct Client { mut: conn net.TcpConn - ssl_conn &openssl.SSLConn = unsafe { 0 } + ssl_conn &openssl.SSLConn = unsafe { nil } reader io.BufferedReader pub: server string diff --git a/vlib/net/urllib/urllib.v b/vlib/net/urllib/urllib.v index f82e5e1c7..6333422ad 100644 --- a/vlib/net/urllib/urllib.v +++ b/vlib/net/urllib/urllib.v @@ -324,7 +324,7 @@ pub struct URL { pub mut: scheme string opaque string // encoded opaque data - user &Userinfo // username and password information + user &Userinfo = unsafe { nil } // username and password information host string // host or host:port path string // path (relative paths may omit leading slash) raw_path string // encoded path hint (see escaped_path method) @@ -529,7 +529,7 @@ fn parse_url(rawurl string, via_request bool) ?URL { } struct ParseAuthorityRes { - user &Userinfo + user &Userinfo = unsafe { nil } host string } diff --git a/vlib/net/websocket/websocket_client.v b/vlib/net/websocket/websocket_client.v index c67b2d1c6..82f1f2235 100644 --- a/vlib/net/websocket/websocket_client.v +++ b/vlib/net/websocket/websocket_client.v @@ -19,7 +19,7 @@ const ( pub struct Client { is_server bool mut: - ssl_conn &openssl.SSLConn // secure connection used when wss is used + ssl_conn &openssl.SSLConn = unsafe { nil } // secure connection used when wss is used flags []Flag // flags used in handshake fragments []Fragment // current fragments message_callbacks []MessageEventHandler // all callbacks on_message @@ -34,11 +34,11 @@ pub: write_timeout i64 pub mut: header http.Header // headers that will be passed when connecting - conn &net.TcpConn // underlying TCP socket connection + conn &net.TcpConn = unsafe { nil } // underlying TCP socket connection nonce_size int = 16 // size of nounce used for masking panic_on_callback bool // set to true of callbacks can panic state State // current state of connection - logger &log.Logger // logger used to log messages + logger &log.Logger = unsafe { nil } // logger used to log messages resource_name string // name of current resource last_pong_ut i64 // last time in unix time we got a pong message } diff --git a/vlib/net/websocket/websocket_server.v b/vlib/net/websocket/websocket_server.v index d05850d6a..228f48f50 100644 --- a/vlib/net/websocket/websocket_server.v +++ b/vlib/net/websocket/websocket_server.v @@ -9,8 +9,8 @@ import rand // Server represents a websocket server connection pub struct Server { mut: - logger &log.Logger // logger used to log - ls &net.TcpListener // listener used to get incoming connection to socket + logger &log.Logger = unsafe { nil } // logger used to log + ls &net.TcpListener = unsafe { nil } // listener used to get incoming connection to socket accept_client_callbacks []AcceptClientFn // accept client callback functions message_callbacks []MessageEventHandler // new message callback functions close_callbacks []CloseEventHandler // close message callback functions @@ -30,8 +30,8 @@ pub: resource_name string // resource that the client access client_key string // unique key of client pub mut: - server &Server - client &Client + server &Server = unsafe { nil } + client &Client = unsafe { nil } } [params] diff --git a/vlib/os/os_android_outside_termux.c.v b/vlib/os/os_android_outside_termux.c.v index e0b457bf0..d66d28a3f 100644 --- a/vlib/os/os_android_outside_termux.c.v +++ b/vlib/os/os_android_outside_termux.c.v @@ -14,7 +14,7 @@ pub enum AssetMode { // See https://developer.android.com/ndk/reference/struct/a-native-activity for more info. struct C.ANativeActivity { pub: - assetManager &AssetManager // Pointer to the Asset Manager instance for the application. + assetManager &AssetManager = unsafe { nil } // Pointer to the Asset Manager instance for the application. clazz voidptr // (jobject) The NativeActivity object handle. env voidptr // (JNIEnv *) JNI context for the main thread of the app. externalDataPath &char // Path to this application's external (removable/mountable) data directory. diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 277d85c80..eccbff99c 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -63,9 +63,9 @@ mut: struct StartupInfo { mut: cb u32 - lp_reserved &u16 - lp_desktop &u16 - lp_title &u16 + lp_reserved &u16 = unsafe { nil } + lp_desktop &u16 = unsafe { nil } + lp_title &u16 = unsafe { nil } dw_x u32 dw_y u32 dw_x_size u32 @@ -76,7 +76,7 @@ mut: dw_flags u32 w_show_window u16 cb_reserved2 u16 - lp_reserved2 &u8 + lp_reserved2 &u8 = unsafe { nil } h_std_input voidptr h_std_output voidptr h_std_error voidptr @@ -428,7 +428,7 @@ pub: // status_ constants code u32 flags u32 - record &ExceptionRecord + record &ExceptionRecord = unsafe { nil } address voidptr param_count u32 // params []voidptr @@ -440,8 +440,8 @@ pub struct ContextRecord { pub struct ExceptionPointers { pub: - exception_record &ExceptionRecord - context_record &ContextRecord + exception_record &ExceptionRecord = unsafe { nil } + context_record &ContextRecord = unsafe { nil } } pub type VectoredExceptionHandler = fn (&ExceptionPointers) u32 diff --git a/vlib/os/process_windows.c.v b/vlib/os/process_windows.c.v index 4b79f6b1d..34f12b8ed 100644 --- a/vlib/os/process_windows.c.v +++ b/vlib/os/process_windows.c.v @@ -48,13 +48,13 @@ pub struct WProcess { pub mut: proc_info ProcessInformation command_line [65536]u8 - child_stdin &u32 + child_stdin &u32 = unsafe { nil } // - child_stdout_read &u32 - child_stdout_write &u32 + child_stdout_read &u32 = unsafe { nil } + child_stdout_write &u32 = unsafe { nil } // - child_stderr_read &u32 - child_stderr_write &u32 + child_stderr_read &u32 = unsafe { nil } + child_stderr_write &u32 = unsafe { nil } } fn (mut p Process) win_spawn_process() int { diff --git a/vlib/pg/pg.v b/vlib/pg/pg.v index 5f77254b5..27ac8f0c6 100644 --- a/vlib/pg/pg.v +++ b/vlib/pg/pg.v @@ -18,7 +18,7 @@ import io pub struct DB { mut: - conn &C.PGconn + conn &C.PGconn = unsafe { nil } } pub struct Row { diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index d2d9c66a5..fd20105e7 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -63,17 +63,17 @@ pub: } struct Picoev { - loop &C.picoev_loop + loop &C.picoev_loop = unsafe { nil } cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) user_data voidptr timeout_secs int max_headers int mut: - date &u8 - buf &u8 + date &u8 = unsafe { nil } + buf &u8 = unsafe { nil } idx [1024]int - out &u8 + out &u8 = unsafe { nil } } [inline] diff --git a/vlib/picohttpparser/response.v b/vlib/picohttpparser/response.v index e0ff045ba..18292c52d 100644 --- a/vlib/picohttpparser/response.v +++ b/vlib/picohttpparser/response.v @@ -3,10 +3,10 @@ module picohttpparser pub struct Response { fd int pub: - date &u8 = unsafe { 0 } - buf_start &u8 = unsafe { 0 } + date &u8 = unsafe { nil } + buf_start &u8 = unsafe { nil } pub mut: - buf &u8 = unsafe { 0 } + buf &u8 = unsafe { nil } } [inline] diff --git a/vlib/sokol/sapp/screenshot.c.v b/vlib/sokol/sapp/screenshot.c.v index 23e1fe3d4..a7379efbf 100644 --- a/vlib/sokol/sapp/screenshot.c.v +++ b/vlib/sokol/sapp/screenshot.c.v @@ -6,7 +6,7 @@ pub struct Screenshot { height int size int mut: - pixels &u8 + pixels &u8 = unsafe { nil } } [manualfree] diff --git a/vlib/sqlite/sqlite.v b/vlib/sqlite/sqlite.v index 16f408302..6c595c30b 100644 --- a/vlib/sqlite/sqlite.v +++ b/vlib/sqlite/sqlite.v @@ -43,8 +43,8 @@ struct C.sqlite3_stmt { [heap] struct Stmt { - stmt &C.sqlite3_stmt - db &DB + stmt &C.sqlite3_stmt = unsafe { nil } + db &DB = unsafe { nil } } struct SQLError { @@ -57,7 +57,7 @@ pub struct DB { pub mut: is_open bool mut: - conn &C.sqlite3 + conn &C.sqlite3 = unsafe { nil } } pub fn (db &DB) str() string { diff --git a/vlib/sync/channels.c.v b/vlib/sync/channels.c.v index 9d76a4a7b..32e6971bd 100644 --- a/vlib/sync/channels.c.v +++ b/vlib/sync/channels.c.v @@ -21,9 +21,9 @@ enum BufferElemStat { struct Subscription { mut: - sem &Semaphore - prev &&Subscription - nxt &Subscription + sem &Semaphore = unsafe { nil } + prev &&Subscription = unsafe { nil } + nxt &Subscription = unsafe { nil } } enum Direction { @@ -32,8 +32,8 @@ enum Direction { } pub struct Channel { - ringbuf &u8 // queue for buffered channels - statusbuf &u8 // flags to synchronize write/read in ringbuf + ringbuf &u8 = unsafe { nil } // queue for buffered channels + statusbuf &u8 = unsafe { nil } // flags to synchronize write/read in ringbuf objsize u32 mut: // atomic writesem Semaphore // to wake thread that wanted to write, but buffer was full @@ -49,8 +49,8 @@ mut: // atomic buf_elem_write_idx u32 buf_elem_read_idx u32 // for select - write_subscriber &Subscription - read_subscriber &Subscription + write_subscriber &Subscription = unsafe { nil } + read_subscriber &Subscription = unsafe { nil } write_sub_mtx u16 read_sub_mtx u16 closed u16 diff --git a/vlib/toml/checker/checker.v b/vlib/toml/checker/checker.v index 5175d43dc..12ad037e7 100644 --- a/vlib/toml/checker/checker.v +++ b/vlib/toml/checker/checker.v @@ -19,7 +19,7 @@ const utf8_max = 0x10FFFF // Checker checks a tree of TOML `ast.Value`'s for common errors. pub struct Checker { - scanner &scanner.Scanner + scanner &scanner.Scanner = unsafe { nil } } // check checks the `ast.Value` and all it's children diff --git a/vlib/toml/decoder/decoder.v b/vlib/toml/decoder/decoder.v index 0c7ae684d..49609dec3 100644 --- a/vlib/toml/decoder/decoder.v +++ b/vlib/toml/decoder/decoder.v @@ -16,7 +16,7 @@ const ( // Decoder decode special sequences in a tree of TOML `ast.Value`'s. pub struct Decoder { - scanner &scanner.Scanner + scanner &scanner.Scanner = unsafe { nil } } // decode decodes certain `ast.Value`'s and all it's children. diff --git a/vlib/toml/parser/parser.v b/vlib/toml/parser/parser.v index 8bd8f0af8..b685ecfd5 100644 --- a/vlib/toml/parser/parser.v +++ b/vlib/toml/parser/parser.v @@ -51,7 +51,7 @@ pub struct Parser { pub: config Config mut: - scanner &scanner.Scanner + scanner &scanner.Scanner = unsafe { nil } prev_tok token.Token tok token.Token peek_tok token.Token @@ -75,7 +75,7 @@ mut: // `decode_values` is used to en- or disable decoding of values with the `decoder.Decoder`. pub struct Config { pub: - scanner &scanner.Scanner + scanner &scanner.Scanner = unsafe { nil } run_checks bool = true decode_values bool = true } diff --git a/vlib/toml/toml.v b/vlib/toml/toml.v index c32fe9442..8abce54e7 100644 --- a/vlib/toml/toml.v +++ b/vlib/toml/toml.v @@ -66,7 +66,7 @@ pub: // A document can be constructed from a `string` buffer or from a file path pub struct Doc { pub: - ast &ast.Root + ast &ast.Root = unsafe { nil } } // parse_file parses the TOML file in `path`. diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index f6510953d..64ebe153b 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -261,7 +261,7 @@ pub mut: typ Type // type of the entire thing (`Foo.bar`) name_type Type // T in `T.name` or typeof in `typeof(expr).name` gkind_field GenericKindField // `T.name` => ast.GenericKindField.name, `T.typ` => ast.GenericKindField.typ, or .unknown - scope &Scope + scope &Scope = unsafe { nil } from_embed_types []Type // holds the type of the embed that the method is called from has_hidden_receiver bool } @@ -554,8 +554,8 @@ pub mut: end_comments []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment` next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl // - source_file &File = unsafe { 0 } - scope &Scope + source_file &File = unsafe { nil } + scope &Scope = unsafe { nil } label_names []string pos token.Pos // function declaration position } @@ -598,7 +598,7 @@ pub mut: concrete_list_pos token.Pos raw_concrete_types []Type free_receiver bool // true if the receiver expression needs to be freed - scope &Scope + scope &Scope = unsafe { nil } from_embed_types []Type // holds the type of the embed that the method is called from comments []Comment } @@ -730,7 +730,7 @@ pub: nr_lines int // number of source code lines in the file (including newlines and comments) nr_bytes int // number of processed source code bytes mod Module // the module of the source file (from `module xyz` at the top) - global_scope &Scope + global_scope &Scope = unsafe { nil } is_test bool // true for _test.v files is_generated bool // true for `[generated] module xyz` files; turn off notices is_translated bool // true for `[translated] module xyz` files; turn off some checks @@ -738,7 +738,7 @@ pub mut: idx int // index in an external container; can be used to refer to the file in a more efficient way, just by its integer index path string // absolute path of the source file - '/projects/v/file.v' path_base string // file name - 'file.v' (useful for tracing) - scope &Scope + scope &Scope = unsafe { nil } stmts []Stmt // all the statements in the source file imports []Import // all the imports auto_imports []string // imports that were implicitely added @@ -808,7 +808,7 @@ pub: mut_pos token.Pos comptime bool pub mut: - scope &Scope + scope &Scope = unsafe { nil } obj ScopeObject mod string name string @@ -932,7 +932,7 @@ pub mut: cond Expr pkg_exist bool stmts []Stmt - scope &Scope + scope &Scope = unsafe { nil } } pub struct UnsafeExpr { @@ -952,7 +952,7 @@ pub mut: comments []Comment is_expr bool typ Type - scope &Scope + scope &Scope = unsafe { nil } } [minify] @@ -981,7 +981,7 @@ pub: pub mut: stmts []Stmt // right side exprs []Expr // left side - scope &Scope + scope &Scope = unsafe { nil } } pub struct SelectExpr { @@ -1033,7 +1033,7 @@ pub mut: cond Expr stmts []Stmt label string // `label: for {` - scope &Scope + scope &Scope = unsafe { nil } } [minify] @@ -1056,7 +1056,7 @@ pub mut: high_type Type kind Kind // array/map/string label string // `label: for {` - scope &Scope + scope &Scope = unsafe { nil } } pub struct ForCStmt { @@ -1072,7 +1072,7 @@ pub mut: inc Stmt // i++; i += 2 stmts []Stmt label string // `label: for {` - scope &Scope + scope &Scope = unsafe { nil } } // #include, #define etc @@ -1338,7 +1338,7 @@ pub: pos token.Pos pub mut: templates []AsmTemplate - scope &Scope + scope &Scope = unsafe { nil } output []AsmIO input []AsmIO global_labels []string // labels defined in assembly block, exported with `.globl` @@ -1573,7 +1573,7 @@ pub: pub mut: exprs []Expr typ Type - scope &Scope + scope &Scope = unsafe { nil } } pub struct SizeOf { @@ -1674,7 +1674,7 @@ pub: has_parens bool // if $() is used, for vfmt method_name string method_pos token.Pos - scope &Scope + scope &Scope = unsafe { nil } left Expr args_var string // diff --git a/vlib/v/ast/scope.v b/vlib/v/ast/scope.v index 02af784a8..47f4e5da5 100644 --- a/vlib/v/ast/scope.v +++ b/vlib/v/ast/scope.v @@ -9,7 +9,7 @@ pub mut: // mut: objects map[string]ScopeObject struct_fields map[string]ScopeStructField - parent &Scope + parent &Scope = unsafe { nil } detached_from_parent bool children []&Scope start_pos int diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 9e507b6fd..d6fd90b70 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -20,7 +20,7 @@ pub mut: dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions imports []string // List of all imports modules []string // Topologically sorted list of all modules registered by the application - global_scope &Scope + global_scope &Scope = unsafe { nil } cflags []cflag.CFlag redefined_fns []string fn_generic_types map[string][][]Type // for generic functions @@ -35,7 +35,7 @@ pub mut: panic_handler FnPanicHandler = default_table_panic_handler panic_userdata voidptr = unsafe { nil } // can be used to pass arbitrary data to panic_handler; panic_npanics int - cur_fn &FnDecl = unsafe { 0 } // previously stored in Checker.cur_fn and Gen.cur_fn + cur_fn &FnDecl = unsafe { nil } // previously stored in Checker.cur_fn and Gen.cur_fn cur_concrete_types []Type // current concrete types, e.g. gostmts int // how many `go` statements there were in the parsed files. // When table.gostmts > 0, __VTHREADS__ is defined, which can be checked with `$if threads {` diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 212a54ddf..a6f967ff0 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -20,8 +20,8 @@ pub: compiled_dir string // contains os.real_path() of the dir of the final file being compiled, or the dir itself when doing `v .` module_path string pub mut: - checker &checker.Checker - transformer &transformer.Transformer + checker &checker.Checker = unsafe { nil } + transformer &transformer.Transformer = unsafe { nil } out_name_c string out_name_js string stats_lines int // size of backend generated source code in lines @@ -29,13 +29,13 @@ pub mut: nr_errors int // accumulated error count of scanner, parser, checker, and builder nr_warnings int // accumulated warning count of scanner, parser, checker, and builder nr_notices int // accumulated notice count of scanner, parser, checker, and builder - pref &pref.Preferences + pref &pref.Preferences = unsafe { nil } module_search_paths []string parsed_files []&ast.File //$if windows { cached_msvc MsvcResult //} - table &ast.Table + table &ast.Table = unsafe { nil } ccoptions CcompilerOptions // // Note: changes in mod `builtin` force invalidation of every other .v file diff --git a/vlib/v/callgraph/callgraph.v b/vlib/v/callgraph/callgraph.v index 114d9d4bf..d8c9e4d74 100644 --- a/vlib/v/callgraph/callgraph.v +++ b/vlib/v/callgraph/callgraph.v @@ -25,11 +25,11 @@ pub fn show(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.File) struct Mapper { pos int mut: - pref &pref.Preferences - table &ast.Table - file &ast.File = unsafe { 0 } - node &ast.Node = unsafe { 0 } - fn_decl &ast.FnDecl = unsafe { 0 } + pref &pref.Preferences = unsafe { nil } + table &ast.Table = unsafe { nil } + file &ast.File = unsafe { nil } + node &ast.Node = unsafe { nil } + fn_decl &ast.FnDecl = unsafe { nil } caller_name string dot_caller_name string is_caller_used bool diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e7737f465..431f0a66b 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -56,10 +56,10 @@ fn all_valid_comptime_idents() []string { [heap; minify] pub struct Checker { - pref &pref.Preferences // Preferences shared from V struct + pref &pref.Preferences = unsafe { nil } // Preferences shared from V struct pub mut: - table &ast.Table - file &ast.File = unsafe { 0 } + table &ast.Table = unsafe { nil } + file &ast.File = unsafe { nil } nr_errors int nr_warnings int nr_notices int diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 6ac3a9f3d..6de21c042 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -541,6 +541,13 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { node.pos) } } + // Check for struct type + if sym.kind == .struct_ && !(sym.info as ast.Struct).is_typedef { + mut checked_structs := []ast.Type{} + checked_structs << field.typ + c.check_ref_fields_initialized(sym.info as ast.Struct, mut checked_structs, + '${node.typ_str}.$field.name', node) + } } } else {} @@ -565,3 +572,27 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { } return node.typ } + +// Recursively check whether the struct type field is initialized +fn (mut c Checker) check_ref_fields_initialized(struct_ &ast.Struct, mut checked_structs []ast.Type, linked_name string, node &ast.StructInit) { + if c.pref.translated || c.file.is_translated { + return + } + for field in struct_.fields { + if field.typ.is_ptr() && !field.typ.has_flag(.shared_f) && !field.has_default_expr { + c.warn('reference field `${linked_name}.$field.name` must be initialized', + node.pos) + continue + } + sym := c.table.sym(field.typ) + if sym.kind == .struct_ { + info := sym.info as ast.Struct + if info.is_typedef || field.typ in checked_structs { + continue + } + checked_structs << field.typ + c.check_ref_fields_initialized(info, mut checked_structs, '${linked_name}.$field.name', + node) + } + } +} diff --git a/vlib/v/checker/tests/reference_field_must_be_initialized.out b/vlib/v/checker/tests/reference_field_must_be_initialized.out index 846e5b75f..83977e253 100644 --- a/vlib/v/checker/tests/reference_field_must_be_initialized.out +++ b/vlib/v/checker/tests/reference_field_must_be_initialized.out @@ -1,5 +1,12 @@ +vlib/v/checker/tests/reference_field_must_be_initialized.vv:8:7: warning: reference field `Node.next.next` must be initialized + 6 | + 7 | fn main(){ + 8 | n := Node{ data: 123 } + | ~~~~~~~~~~~~~~~~~ + 9 | eprintln('n.data: $n.data') + 10 | } vlib/v/checker/tests/reference_field_must_be_initialized.vv:8:7: error: reference field `Node.next` must be initialized - 6 | + 6 | 7 | fn main(){ 8 | n := Node{ data: 123 } | ~~~~~~~~~~~~~~~~~ diff --git a/vlib/v/checker/tests/struct_field_reference_type_err.out b/vlib/v/checker/tests/struct_field_reference_type_err.out index 1650a630c..11c750952 100644 --- a/vlib/v/checker/tests/struct_field_reference_type_err.out +++ b/vlib/v/checker/tests/struct_field_reference_type_err.out @@ -1,5 +1,12 @@ +vlib/v/checker/tests/struct_field_reference_type_err.vv:12:16: warning: reference field `Animal.duck.age` must be initialized + 10 | + 11 | fn main() { + 12 | mut animal := Animal{ + | ~~~~~~~ + 13 | ageee: 20 + 14 | } vlib/v/checker/tests/struct_field_reference_type_err.vv:17:3: error: reference field must be initialized with reference - 15 | + 15 | 16 | animal.duck = Duck{ 17 | age: animal.ageee | ~~~~~~~~~~~~~~~~~ diff --git a/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out new file mode 100644 index 000000000..b9c2e2e1e --- /dev/null +++ b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv:11:7: warning: reference field `Outer.c.b` must be initialized + 9 | + 10 | fn main() { + 11 | o := Outer{} + | ~~~~~~~ + 12 | dump(o) + 13 | } diff --git a/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv new file mode 100644 index 000000000..3f4960485 --- /dev/null +++ b/vlib/v/checker/tests/struct_ref_fields_uninitialized_err.vv @@ -0,0 +1,13 @@ +struct ContainsRef { + a &int = unsafe { nil } + b &int +} + +struct Outer { + c ContainsRef +} + +fn main() { + o := Outer{} + dump(o) +} diff --git a/vlib/v/embed_file/embed_file.v b/vlib/v/embed_file/embed_file.v index afca2ceed..b6366f585 100644 --- a/vlib/v/embed_file/embed_file.v +++ b/vlib/v/embed_file/embed_file.v @@ -12,8 +12,8 @@ pub struct EmbedFileData { apath string compression_type string mut: - compressed &u8 - uncompressed &u8 + compressed &u8 = unsafe { nil } + uncompressed &u8 = unsafe { nil } free_compressed bool free_uncompressed bool pub: @@ -100,7 +100,7 @@ pub struct EmbedFileIndexEntry { id int path string algo string - data &u8 + data &u8 = unsafe { nil } } // find_index_entry_by_path is used internally by the V compiler: diff --git a/vlib/v/eval/eval.v b/vlib/v/eval/eval.v index d2253094a..4fc17d273 100644 --- a/vlib/v/eval/eval.v +++ b/vlib/v/eval/eval.v @@ -21,7 +21,7 @@ type Symbol = Object | ast.EmptyStmt | ast.FnDecl pub struct Eval { pref &pref.Preferences pub mut: - table &ast.Table + table &ast.Table = unsafe { nil } mods map[string]map[string]Symbol future_register_consts map[string]map[string]map[string]ast.ConstField // mod:file:name:field local_vars map[string]Var diff --git a/vlib/v/eval/object.v b/vlib/v/eval/object.v index f71d84b27..d0934fc9c 100644 --- a/vlib/v/eval/object.v +++ b/vlib/v/eval/object.v @@ -141,7 +141,7 @@ pub mut: } pub struct Ptr { - val &Object + val &Object = unsafe { nil } } // override the autogenerated str, since it does not work diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 32e60a978..701009269 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -18,8 +18,8 @@ const ( pub struct Fmt { pub mut: file ast.File - table &ast.Table - pref &pref.Preferences + table &ast.Table = unsafe { nil } + pref &pref.Preferences = unsafe { nil } is_debug bool out strings.Builder out_imports strings.Builder diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 1b24c4aa7..884b90a48 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -44,11 +44,11 @@ fn string_array_to_map(a []string) map[string]bool { } pub struct Gen { - pref &pref.Preferences + pref &pref.Preferences = unsafe { nil } field_data_type ast.Type // cache her to avoid map lookups module_built string timers_should_print bool - table &ast.Table + table &ast.Table = unsafe { nil } mut: out strings.Builder cheaders strings.Builder @@ -78,11 +78,11 @@ mut: sql_buf strings.Builder // for writing exprs to args via `sqlite3_bind_int()` etc global_const_defs map[string]GlobalConstDef sorted_global_const_names []string - file &ast.File + file &ast.File = unsafe { nil } unique_file_path_hash u64 // a hash of file.path, used for making auxilary fn generation unique (like `compare_xyz`) - fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0 + fn_decl &ast.FnDecl = unsafe { nil } // pointer to the FnDecl we are currently inside otherwise 0 last_fn_c_name string - tmp_count int // counter for unique tmp vars (_tmp1, _tmp2 etc); resets at the start of each fn. + tmp_count int // counter for unique tmp vars (_tmp1, _tmp2 etc); resets at the start of each fn. tmp_count_af int // a separate tmp var counter for autofree fn calls tmp_count_declarations int // counter for unique tmp names (_d1, _d2 etc); does NOT reset, used for C declarations global_tmp_count int // like tmp_count but global and not resetted in each function @@ -108,7 +108,7 @@ mut: chan_push_optionals map[string]string // types for `ch <- x or {...}` mtxs string // array of mutexes if the `lock` has multiple variables labeled_loops map[string]&ast.Stmt - inner_loop &ast.Stmt + inner_loop &ast.Stmt = unsafe { nil } shareds map[int]string // types with hidden mutex for which decl has been emitted inside_ternary int // ?: comma separated statements on a single line inside_map_postfix bool // inside map++/-- postfix expr @@ -208,7 +208,7 @@ mut: // main_fn_decl_node ast.FnDecl cur_mod ast.Module cur_concrete_types []ast.Type // do not use table.cur_concrete_types because table is global, so should not be accessed by different threads - cur_fn &ast.FnDecl = unsafe { 0 } // same here + cur_fn &ast.FnDecl = unsafe { nil } // same here cur_lock ast.LockExpr autofree_methods map[int]bool generated_free_methods map[int]bool diff --git a/vlib/v/gen/golang/golang.v b/vlib/v/gen/golang/golang.v index d0c2b7e19..c215adca6 100644 --- a/vlib/v/gen/golang/golang.v +++ b/vlib/v/gen/golang/golang.v @@ -17,8 +17,8 @@ const ( pub struct Gen { pub mut: - table &ast.Table - pref &pref.Preferences + table &ast.Table = unsafe { nil } + pref &pref.Preferences = unsafe { nil } // is_debug bool out strings.Builder out_imports strings.Builder diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 1799aa0c7..e57ab5bed 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -46,13 +46,13 @@ mut: struct JsGen { pref &pref.Preferences mut: - table &ast.Table + table &ast.Table = unsafe { nil } definitions strings.Builder - ns &Namespace + ns &Namespace = unsafe { nil } namespaces map[string]&Namespace - doc &JsDoc + doc &JsDoc = unsafe { nil } enable_doc bool - file &ast.File + file &ast.File = unsafe { nil } tmp_count int inside_ternary bool inside_or bool @@ -65,9 +65,9 @@ mut: is_test bool stmt_start_pos int defer_stmts []ast.DeferStmt - fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0 + fn_decl &ast.FnDecl = unsafe { nil } // pointer to the FnDecl we are currently inside otherwise 0 generated_str_fns []StrType - str_types []StrType // types that need automatic str() generation + str_types []StrType // types that need automatic str() generation copy_types []StrType // types that need to be deep copied generated_copy_fns []StrType array_fn_definitions []string // array equality functions that have been defined @@ -84,7 +84,7 @@ mut: cast_stack []ast.Type call_stack []ast.CallExpr is_vlines_enabled bool // is it safe to generate #line directives when -g is passed - sourcemap &sourcemap.SourceMap // maps lines in generated javascrip file to original source files and line + sourcemap &sourcemap.SourceMap = unsafe { nil } // maps lines in generated javascrip file to original source files and line comptime_var_type_map map[string]ast.Type defer_ifdef string cur_concrete_types []ast.Type diff --git a/vlib/v/gen/js/jsdoc.v b/vlib/v/gen/js/jsdoc.v index 359687e3a..ba3ea05f4 100644 --- a/vlib/v/gen/js/jsdoc.v +++ b/vlib/v/gen/js/jsdoc.v @@ -4,7 +4,7 @@ import v.ast struct JsDoc { mut: - gen &JsGen + gen &JsGen = unsafe { nil } } fn new_jsdoc(gen &JsGen) &JsDoc { diff --git a/vlib/v/gen/js/util.v b/vlib/v/gen/js/util.v index d2d66d063..faedcf162 100644 --- a/vlib/v/gen/js/util.v +++ b/vlib/v/gen/js/util.v @@ -5,11 +5,11 @@ import v.ast struct Type { // typ is the original type typ ast.Type [required] - sym &ast.TypeSymbol [required] + sym &ast.TypeSymbol [required] = unsafe { nil } // unaliased is `typ` once aliased have been resolved // it may not contain informations such as flags and nr_muls unaliased ast.Type [required] - unaliased_sym &ast.TypeSymbol [required] + unaliased_sym &ast.TypeSymbol [required] = unsafe { nil } } // unwrap returns the following variants of a type: diff --git a/vlib/v/gen/native/amd64.v b/vlib/v/gen/native/amd64.v index 53c918eed..29e693b87 100644 --- a/vlib/v/gen/native/amd64.v +++ b/vlib/v/gen/native/amd64.v @@ -5,7 +5,7 @@ import v.token pub struct Amd64 { mut: - g &Gen + g &Gen = unsafe { nil } // arm64 specific stuff for code generation is_16bit_aligned bool } diff --git a/vlib/v/gen/native/arm64.v b/vlib/v/gen/native/arm64.v index 097ff490e..f12273658 100644 --- a/vlib/v/gen/native/arm64.v +++ b/vlib/v/gen/native/arm64.v @@ -38,7 +38,7 @@ enum Arm64Register { pub struct Arm64 { mut: - g &Gen + g &Gen = unsafe { nil } // arm64 specific stuff for code generation } diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index 206529bd8..2aaeab8b9 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -23,10 +23,10 @@ mut: [heap; minify] pub struct Gen { out_name string - pref &pref.Preferences // Preferences shared from V struct + pref &pref.Preferences = unsafe { nil } // Preferences shared from V struct mut: code_gen CodeGen - table &ast.Table + table &ast.Table = unsafe { nil } buf []u8 sect_header_name_pos int offset i64 @@ -48,7 +48,7 @@ mut: nlines int callpatches []CallPatch strs []String - labels &LabelTable + labels &LabelTable = unsafe { nil } defer_stmts []ast.DeferStmt builtins map[string]BuiltinFn structs []Struct diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index 537c8c7e6..74d7b20c6 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -9,12 +9,12 @@ import v.pref pub struct Walker { pub mut: - table &ast.Table + table &ast.Table = unsafe { nil } used_fns map[string]bool // used_fns['println'] == true used_consts map[string]bool // used_consts['os.args'] == true used_globals map[string]bool n_asserts int - pref &pref.Preferences + pref &pref.Preferences = unsafe { nil } mut: files []&ast.File all_fns map[string]ast.FnDecl diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index c51c02714..e4fd3867b 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -16,7 +16,7 @@ import hash.fnv1a [minify] pub struct Parser { - pref &pref.Preferences + pref &pref.Preferences = unsafe { nil } mut: file_base string // "hello.v" file_name string // "/home/user/hello.v" @@ -28,7 +28,7 @@ mut: tok token.Token prev_tok token.Token peek_tok token.Token - table &ast.Table + table &ast.Table = unsafe { nil } language ast.Language fn_language ast.Language // .c for `fn C.abcd()` declarations expr_level int // prevent too deep recursions for pathological programs @@ -68,7 +68,7 @@ mut: is_translated bool // `[translated] module abc` - mark a file as translated, to relax some compiler checks for translated code. attrs []ast.Attr // attributes before next decl stmt expr_mod string // for constructing full type names in parse_type() - scope &ast.Scope + scope &ast.Scope = unsafe { nil } imports map[string]string // alias => mod_name ast_imports []ast.Import // mod_names used_imports []string // alias @@ -92,7 +92,7 @@ mut: script_mode bool script_mode_start_token token.Token pub mut: - scanner &scanner.Scanner + scanner &scanner.Scanner = unsafe { nil } errors []errors.Error warnings []errors.Warning notices []errors.Notice @@ -371,10 +371,10 @@ mut: mu &sync.Mutex mu2 &sync.Mutex paths []string - table &ast.Table + table &ast.Table = unsafe { nil } parsed_ast_files []&ast.File - pref &pref.Preferences - global_scope &ast.Scope + pref &pref.Preferences = unsafe { nil } + global_scope &ast.Scope = unsafe { nil } } fn (mut q Queue) run() { diff --git a/vlib/v/pkgconfig/main.v b/vlib/v/pkgconfig/main.v index e3ff15513..4872ce1e3 100644 --- a/vlib/v/pkgconfig/main.v +++ b/vlib/v/pkgconfig/main.v @@ -5,7 +5,7 @@ import strings pub struct Main { pub mut: - opt &MainOptions + opt &MainOptions = unsafe { nil } res string has_actions bool } diff --git a/vlib/v/transformer/transformer.v b/vlib/v/transformer/transformer.v index 73951bf5b..78b6fe9dc 100644 --- a/vlib/v/transformer/transformer.v +++ b/vlib/v/transformer/transformer.v @@ -8,7 +8,7 @@ pub struct Transformer { pref &pref.Preferences pub mut: index &IndexState - table &ast.Table = unsafe { 0 } + table &ast.Table = unsafe { nil } mut: is_assert bool } diff --git a/vlib/vweb/sse/sse.v b/vlib/vweb/sse/sse.v index 1e0c44488..18fb8e4e7 100644 --- a/vlib/vweb/sse/sse.v +++ b/vlib/vweb/sse/sse.v @@ -24,7 +24,7 @@ import strings pub struct SSEConnection { pub mut: headers map[string]string - conn &net.TcpConn + conn &net.TcpConn = unsafe { nil } write_timeout time.Duration = 600 * time.second } diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index d45113a8e..04693d356 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -153,7 +153,7 @@ pub mut: page_gen_start i64 // TCP connection to client. // But beware, do not store it for further use, after request processing vweb will close connection. - conn &net.TcpConn + conn &net.TcpConn = unsafe { nil } static_files map[string]string static_mime_types map[string]string // Map containing query params for the route. diff --git a/vlib/x/json2/decoder.v b/vlib/x/json2/decoder.v index 2a42d5163..a80faa19b 100644 --- a/vlib/x/json2/decoder.v +++ b/vlib/x/json2/decoder.v @@ -87,7 +87,7 @@ pub fn (err UnknownTokenError) msg() string { struct Parser { mut: - scanner &Scanner + scanner &Scanner = unsafe { nil } p_tok Token tok Token n_tok Token diff --git a/vlib/x/ttf/render_bmp.v b/vlib/x/ttf/render_bmp.v index b98fb6cc2..cbf0d4fc9 100644 --- a/vlib/x/ttf/render_bmp.v +++ b/vlib/x/ttf/render_bmp.v @@ -18,8 +18,8 @@ import math pub struct BitMap { pub mut: - tf &TTF_File - buf &u8 = unsafe { 0 } // pointer to the memory buffer + tf &TTF_File = unsafe { nil } + buf &u8 = unsafe { nil } // pointer to the memory buffer buf_size int // allocated buf size in bytes width int = 1 // width of the buffer height int = 1 // height of the buffer diff --git a/vlib/x/ttf/render_sokol_cpu.v b/vlib/x/ttf/render_sokol_cpu.v index 051135fea..a6052a300 100644 --- a/vlib/x/ttf/render_sokol_cpu.v +++ b/vlib/x/ttf/render_sokol_cpu.v @@ -19,7 +19,7 @@ import sokol.gfx pub struct TTF_render_Sokol { pub mut: - bmp &BitMap // Base bitmap render + bmp &BitMap = unsafe { nil } // Base bitmap render // rendering fields sg_img gfx.Image // sokol image scale_reduct f32 = 2.0 // scale of the cpu texture for filtering -- 2.30.2