1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix nested struct reference type field initialized check. (fix: #15741) (#15752)

This commit is contained in:
shove 2022-09-15 12:59:31 +08:00 committed by GitHub
parent 5719344653
commit 8b962f8446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
111 changed files with 288 additions and 223 deletions

View File

@ -82,7 +82,7 @@ struct GenVC {
// flag options // flag options
options FlagOptions options FlagOptions
mut: mut:
logger &log.Log logger &log.Log = unsafe { nil }
// true if error was experienced running generate // true if error was experienced running generate
gen_error bool gen_error bool
} }
@ -91,7 +91,7 @@ mut:
struct WebhookServer { struct WebhookServer {
vweb.Context vweb.Context
mut: mut:
gen_vc &GenVC = unsafe { 0 } // initialized in init_server gen_vc &GenVC = unsafe { nil } // initialized in init_server
} }
// storage for flag options // storage for flag options

View File

@ -140,8 +140,8 @@ fn json(file string) string {
// the ast tree // the ast tree
struct Tree { struct Tree {
table &ast.Table table &ast.Table = unsafe { nil }
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
mut: mut:
root Node // the root of tree root Node // the root of tree
} }

View File

@ -35,7 +35,7 @@ mut:
// parser context in the worker processes: // parser context in the worker processes:
table ast.Table table ast.Table
scope ast.Scope scope ast.Scope
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
period_ms int // print periodic progress period_ms int // print periodic progress
stop_print bool // stop printing the periodic progress stop_print bool // stop printing the periodic progress
} }

View File

@ -84,7 +84,7 @@ mut:
vfiles []VFileStat vfiles []VFileStat
opts []string opts []string
rerun_channel chan RerunCommand rerun_channel chan RerunCommand
child_process &os.Process child_process &os.Process = unsafe { nil }
is_exiting bool // set by SIGINT/Ctrl-C is_exiting bool // set by SIGINT/Ctrl-C
v_cycles int // how many times the worker has restarted the V compiler 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 scan_cycles int // how many times the worker has scanned for source file changes

View File

@ -7,7 +7,7 @@ import time
struct App { struct App {
mut: mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
touch TouchInfo touch TouchInfo
ui Ui ui Ui
theme &Theme = themes[0] theme &Theme = themes[0]
@ -18,7 +18,7 @@ mut:
state GameState = .play state GameState = .play
tile_format TileFormat = .normal tile_format TileFormat = .normal
moves int moves int
perf &Perf = unsafe { 0 } perf &Perf = unsafe { nil }
is_ai_mode bool is_ai_mode bool
} }

View File

@ -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] 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] second_hand []f32 = [f32(345.8), 38.5, 350, 34.3, 354.2000, 38.5, 358.75, 427, 341.25, 427]
mut: mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
draw_flag bool = true draw_flag bool = true
dpi_scale f32 = 1.0 dpi_scale f32 = 1.0
} }

View File

@ -6,8 +6,8 @@ import rand
struct App { struct App {
mut: mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
ui &objects.UIParams = unsafe { 0 } ui &objects.UIParams = unsafe { nil }
rockets []objects.Rocket rockets []objects.Rocket
frames [][]objects.Rocket frames [][]objects.Rocket
// i thought about using a fixed fifo queue for the frames but the array // i thought about using a fixed fifo queue for the frames but the array

View File

@ -66,7 +66,7 @@ fn (p Pipe) is_out() bool {
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
background gg.Image background gg.Image
bird gg.Image bird gg.Image
pipetop gg.Image pipetop gg.Image

View File

@ -26,7 +26,7 @@ fn print_automaton(app &App) {
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
a automaton.Automaton a automaton.Automaton
} }

View File

@ -48,8 +48,8 @@ pub fn (a &A2D) clear() {
// /////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////
pub struct Automaton { pub struct Automaton {
pub mut: pub mut:
field &A2D field &A2D = unsafe { nil }
new_field &A2D new_field &A2D = unsafe { nil }
} }
fn new_automaton(ftext string) Automaton { fn new_automaton(ftext string) Automaton {

View File

@ -9,7 +9,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
} }
fn main() { fn main() {

View File

@ -7,8 +7,8 @@ const rate = f32(1) / 60 * 10
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
anim &Anim anim &Anim = unsafe { nil }
} }
struct Anim { struct Anim {

View File

@ -13,8 +13,8 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
dropped_file_list []string = []string{} dropped_file_list []string = []string{}
} }
fn main() { fn main() {

View File

@ -5,7 +5,7 @@ import gx
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
pixels []f32 pixels []f32
} }

View File

@ -31,7 +31,7 @@ fn (v &ViewRect) height() f64 {
struct AppState { struct AppState {
mut: mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
iidx int iidx int
pixels &u32 = unsafe { vcalloc(pwidth * pheight * sizeof(u32)) } 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 npixels &u32 = unsafe { vcalloc(pwidth * pheight * sizeof(u32)) } // all drawing happens here, results are swapped at the end

View File

@ -9,7 +9,7 @@ const pbytes = 4
struct AppState { struct AppState {
mut: mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
istream_idx int istream_idx int
pixels [pheight][pwidth]u32 pixels [pheight][pwidth]u32
} }

View File

@ -60,7 +60,7 @@ Let my heart be still a moment and this mystery explore;—
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
} }
fn main() { fn main() {

View File

@ -11,7 +11,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
image gg.Image image gg.Image
} }

View File

@ -37,7 +37,7 @@ mut:
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
image gg.Image image gg.Image
stars []Star stars []Star
v_letters []VLetter v_letters []VLetter

View File

@ -18,7 +18,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
ch chan i64 ch chan i64
counter i64 counter i64
} }

View File

@ -8,7 +8,7 @@ import time
struct Game { struct Game {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
x int x int
y int y int
dy int dy int

View File

@ -12,7 +12,7 @@ const (
struct Context { struct Context {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
} }
fn main() { fn main() {

View File

@ -35,7 +35,7 @@ struct TrayInfo {
[heap] [heap]
struct MyApp { struct MyApp {
mut: mut:
tray_info &TrayInfo tray_info &TrayInfo = unsafe { nil }
} }
fn (app &MyApp) on_menu_item_click(item TrayMenuItem) { fn (app &MyApp) on_menu_item_click(item TrayMenuItem) {

View File

@ -84,7 +84,7 @@ fn (v Vec) norm() Vec {
struct Image { struct Image {
width int width int
height int height int
data &Vec data &Vec = unsafe { nil }
} }
fn new_image(w int, h int) Image { fn new_image(w int, h int) Image {

View File

@ -19,7 +19,7 @@ pub:
request_chan chan &sim.SimRequest request_chan chan &sim.SimRequest
result_chan chan &sim.SimResult result_chan chan &sim.SimResult
pub mut: pub mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
iidx int iidx int
pixels []u32 pixels []u32
} }

View File

@ -36,7 +36,7 @@ enum Direction {
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
score int score int
snake []Pos snake []Pos
dir Direction dir Direction

View File

@ -50,7 +50,7 @@ fn (mut h HighScore) load() {
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
score int score int
best HighScore best HighScore
snake []Pos snake []Pos

View File

@ -25,7 +25,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
pip_3d sgl.Pipeline pip_3d sgl.Pipeline
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool

View File

@ -36,7 +36,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
pip_3d sgl.Pipeline pip_3d sgl.Pipeline
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool

View File

@ -37,7 +37,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool
frame_count int frame_count int

View File

@ -37,7 +37,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool
frame_count int frame_count int

View File

@ -32,7 +32,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool
frame_count int frame_count int

View File

@ -98,8 +98,8 @@ pub mut:
// shader data for the rendering // shader data for the rendering
pub struct Shader_data { pub struct Shader_data {
pub mut: pub mut:
vs_data &Tmp_vs_param vs_data &Tmp_vs_param = unsafe { nil }
vs_len int vs_len int
fs_data &Tmp_fs_param fs_data &Tmp_fs_param = unsafe { nil }
fs_len int fs_len int
} }

View File

@ -45,7 +45,7 @@ const (
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool
frame_count int frame_count int

View File

@ -56,7 +56,7 @@ Let my heart be still a moment and this mystery explore;—
struct AppState { struct AppState {
mut: mut:
pass_action gfx.PassAction pass_action gfx.PassAction
fons &fontstash.Context fons &fontstash.Context = unsafe { nil }
font_normal int font_normal int
inited bool inited bool
} }

View File

@ -9,7 +9,7 @@ mut:
gframe int // the current graphical frame gframe int // the current graphical frame
frame_0 int // offset of the current audio frames, relative to the start of the music 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 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) { fn my_audio_stream_callback(buffer &f32, num_frames int, num_channels int, mut acontext AppState) {

View File

@ -18,7 +18,7 @@ struct Point {
struct App { struct App {
mut: mut:
tui &tui.Context = unsafe { 0 } tui &tui.Context = unsafe { nil }
points []Point points []Point
color tui.Color = colors[0] color tui.Color = colors[0]
color_idx int color_idx int

View File

@ -2,7 +2,7 @@ import term.ui as tui
struct App { struct App {
mut: mut:
tui &tui.Context = unsafe { 0 } tui &tui.Context = unsafe { nil }
} }
fn event(e &tui.Event, x voidptr) { fn event(e &tui.Event, x voidptr) {

View File

@ -19,11 +19,11 @@ const (
[heap] [heap]
struct App { struct App {
mut: mut:
tui &ui.Context = unsafe { 0 } tui &ui.Context = unsafe { nil }
mode Mode = Mode.menu mode Mode = Mode.menu
width int width int
height int height int
game &Game = unsafe { 0 } game &Game = unsafe { nil }
dt f32 dt f32
ticks i64 ticks i64
} }
@ -191,7 +191,7 @@ fn (mut a App) draw_game() {
struct Player { struct Player {
mut: mut:
game &Game game &Game = unsafe { nil }
pos Vec pos Vec
racket_size int = 4 racket_size int = 4
score int score int
@ -242,7 +242,7 @@ fn (mut b Ball) update(dt f32) {
[heap] [heap]
struct Game { struct Game {
mut: mut:
app &App = unsafe { 0 } app &App = unsafe { nil }
players []Player players []Player
ball Ball ball Ball
} }

View File

@ -12,7 +12,7 @@ mut:
struct App { struct App {
mut: mut:
tui &tui.Context = unsafe { 0 } tui &tui.Context = unsafe { nil }
rects []Rect rects []Rect
cur_rect Rect cur_rect Rect
is_drag bool is_drag bool

View File

@ -90,7 +90,7 @@ const (
struct App { struct App {
mut: mut:
ui &ui.Context = unsafe { 0 } ui &ui.Context = unsafe { nil }
header_text []string header_text []string
mouse_pos Point mouse_pos Point
msg string msg string

View File

@ -57,8 +57,8 @@ pub:
struct App { struct App {
mut: mut:
tui &tui.Context = unsafe { 0 } tui &tui.Context = unsafe { nil }
ed &Buffer = unsafe { 0 } ed &Buffer = unsafe { nil }
current_file int current_file int
files []string files []string
status string status string

View File

@ -71,7 +71,7 @@ mut:
// snake representation // snake representation
struct Snake { struct Snake {
mut: mut:
app &App app &App = unsafe { nil }
direction Orientation direction Orientation
body []BodyPart body []BodyPart
velocity Vec = Vec{ velocity Vec = Vec{
@ -247,7 +247,7 @@ mut:
} }
captured bool captured bool
color termui.Color = grey color termui.Color = grey
app &App app &App = unsafe { nil }
} }
// randomize spawn the rat in a new spot within the playable field // randomize spawn the rat in a new spot within the playable field
@ -259,7 +259,7 @@ fn (mut r Rat) randomize() {
[heap] [heap]
struct App { struct App {
mut: mut:
termui &termui.Context = unsafe { 0 } termui &termui.Context = unsafe { nil }
snake Snake snake Snake
rat Rat rat Rat
width int width int

View File

@ -20,7 +20,7 @@ const (
// UI // UI
struct App_data { struct App_data {
pub mut: pub mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
sg_img gfx.Image sg_img gfx.Image
init_flag bool init_flag bool
frame_c int frame_c int

View File

@ -60,7 +60,7 @@ enum Viewer_state {
struct App { struct App {
mut: mut:
gg &gg.Context gg &gg.Context = unsafe { nil }
pip_viewer sgl.Pipeline pip_viewer sgl.Pipeline
texture gfx.Image texture gfx.Image
init_flag bool init_flag bool
@ -88,13 +88,13 @@ mut:
img_h int img_h int
img_ratio f32 = 1.0 img_ratio f32 = 1.0
// item list // item list
item_list &Item_list item_list &Item_list = unsafe { nil }
// Text info and help // Text info and help
show_info_flag bool = true show_info_flag bool = true
show_help_flag bool show_help_flag bool
// zip container // zip container
zip &szip.Zip // pointer to the szip structure zip &szip.Zip = unsafe { nil } // pointer to the szip structure
zip_index int = -1 // index of the zip contaire item zip_index int = -1 // index of the zip contaire item
// memory buffer // memory buffer
mem_buf voidptr // buffer used to load items from files/containers mem_buf voidptr // buffer used to load items from files/containers
mem_buf_size int // size of the buffer mem_buf_size int // size of the buffer

View File

@ -37,7 +37,7 @@ pub mut:
f_size_of_struct u32 f_size_of_struct u32
f_key voidptr f_key voidptr
f_line_number u32 f_line_number u32
f_file_name &u8 f_file_name &u8 = unsafe { nil }
f_address u64 f_address u64
} }
@ -214,7 +214,7 @@ pub:
// status_ constants // status_ constants
code u32 code u32
flags u32 flags u32
record &ExceptionRecord record &ExceptionRecord = unsafe { nil }
address voidptr address voidptr
param_count u32 param_count u32
// params []voidptr // params []voidptr
@ -226,8 +226,8 @@ struct ContextRecord {
struct ExceptionPointers { struct ExceptionPointers {
pub: pub:
exception_record &ExceptionRecord exception_record &ExceptionRecord = unsafe { nil }
context_record &ContextRecord context_record &ContextRecord = unsafe { nil }
} }
type VectoredExceptionHandler = fn (&ExceptionPointers) int type VectoredExceptionHandler = fn (&ExceptionPointers) int

View File

@ -85,9 +85,9 @@ mut:
deletes u32 // count deletes u32 // count
// array allocated (with `cap` bytes) on first deletion // array allocated (with `cap` bytes) on first deletion
// has non-zero element when key deleted // has non-zero element when key deleted
all_deleted &u8 all_deleted &u8 = unsafe { nil }
keys &u8 keys &u8 = unsafe { nil }
values &u8 values &u8 = unsafe { nil }
} }
[inline] [inline]

View File

@ -27,7 +27,7 @@ pub mut:
disable_flags bool disable_flags bool
sort_flags bool sort_flags bool
sort_commands bool sort_commands bool
parent &Command = unsafe { 0 } parent &Command = unsafe { nil }
commands []Command commands []Command
flags []Flag flags []Flag
required_args int required_args int

View File

@ -15,9 +15,9 @@ struct WndClassEx {
h_icon C.HICON h_icon C.HICON
h_cursor C.HCURSOR h_cursor C.HCURSOR
hbr_background C.HBRUSH hbr_background C.HBRUSH
lpsz_menu_name &u16 // LPCWSTR lpsz_menu_name &u16 = unsafe { nil } // LPCWSTR
lpsz_class_name &u16 lpsz_class_name &u16 = unsafe { nil }
h_icon_sm &u16 h_icon_sm &u16 = unsafe { nil }
} }
fn C.RegisterClassEx(class &WndClassEx) int fn C.RegisterClassEx(class &WndClassEx) int

View File

@ -155,7 +155,7 @@ struct Property {
actual_type Atom actual_type Atom
actual_format int actual_format int
nitems u64 nitems u64
data &u8 data &u8 = unsafe { nil }
} }
// new_clipboard returns a new `Clipboard` instance allocated on the heap. // new_clipboard returns a new `Clipboard` instance allocated on the heap.

View File

@ -265,8 +265,8 @@ struct Chunk {
mut: mut:
prev_foot usize prev_foot usize
head usize head usize
prev &Chunk prev &Chunk = unsafe { nil }
next &Chunk next &Chunk = unsafe { nil }
} }
[heap] [heap]
@ -274,7 +274,7 @@ struct Segment {
mut: mut:
base voidptr base voidptr
size usize size usize
next &Segment next &Segment = unsafe { nil }
flags u32 flags u32
} }

View File

@ -4,12 +4,12 @@ pub type EventHandlerFn = fn (receiver voidptr, args voidptr, sender voidptr)
pub struct Publisher { pub struct Publisher {
mut: mut:
registry &Registry registry &Registry = unsafe { nil }
} }
pub struct Subscriber { pub struct Subscriber {
mut: mut:
registry &Registry registry &Registry = unsafe { nil }
} }
struct Registry { struct Registry {
@ -26,9 +26,9 @@ struct EventHandler {
pub struct EventBus { pub struct EventBus {
pub mut: pub mut:
registry &Registry registry &Registry = unsafe { nil }
publisher &Publisher publisher &Publisher = unsafe { nil }
subscriber &Subscriber subscriber &Subscriber = unsafe { nil }
} }
pub fn new() &EventBus { pub fn new() &EventBus {

View File

@ -38,7 +38,7 @@ pub struct C.FONStextIter {
codepoint u32 codepoint u32
isize i16 isize i16
iblur i16 iblur i16
font &C.FONSfont font &C.FONSfont = unsafe { nil }
prevGlyphIndex int prevGlyphIndex int
str &u8 str &u8
next &u8 next &u8

View File

@ -123,7 +123,7 @@ pub mut:
timage_pip sgl.Pipeline timage_pip sgl.Pipeline
config Config config Config
user_data voidptr user_data voidptr
ft &FT ft &FT = unsafe { nil }
font_inited bool font_inited bool
ui_mode bool // do not redraw everything 60 times/second, but only when the user requests 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 frame u64 // the current frame counted from the start of the application; always increasing

View File

@ -5,7 +5,7 @@ import gx
struct App { struct App {
mut: mut:
gg &gg.Context = unsafe { 0 } gg &gg.Context = unsafe { nil }
rotation f32 = f32(0) rotation f32 = f32(0)
edge int = 3 edge int = 3
} }

View File

@ -11,7 +11,7 @@ import os.font
struct FT { struct FT {
pub: pub:
fons &fontstash.Context fons &fontstash.Context = unsafe { nil }
font_normal int font_normal int
font_bold int font_bold int
font_mono int font_mono int

View File

@ -1,7 +1,7 @@
module mysql module mysql
pub struct Result { pub struct Result {
result &C.MYSQL_RES result &C.MYSQL_RES = unsafe { nil }
} }
pub struct Row { pub struct Row {

View File

@ -36,7 +36,7 @@ const (
struct DTP { struct DTP {
mut: mut:
conn &net.TcpConn conn &net.TcpConn = unsafe { nil }
reader io.BufferedReader reader io.BufferedReader
ip string ip string
port int port int
@ -61,7 +61,7 @@ fn (mut dtp DTP) close() {
struct FTP { struct FTP {
mut: mut:
conn &net.TcpConn conn &net.TcpConn = unsafe { nil }
reader io.BufferedReader reader io.BufferedReader
buffer_size int buffer_size int
} }

View File

@ -9,7 +9,7 @@ import os
// https://www.w3.org/TR/WD-DOM/introduction.html // https://www.w3.org/TR/WD-DOM/introduction.html
pub struct DocumentObjectModel { pub struct DocumentObjectModel {
mut: mut:
root &Tag root &Tag = unsafe { nil }
constructed bool constructed bool
btree BTree btree BTree
all_tags []&Tag all_tags []&Tag

View File

@ -5,7 +5,7 @@ import strings
struct LexicalAttributes { struct LexicalAttributes {
mut: mut:
current_tag &Tag current_tag &Tag = unsafe { nil }
open_tag bool open_tag bool
open_code bool open_code bool
open_string int open_string int

View File

@ -16,7 +16,7 @@ pub mut:
children []&Tag children []&Tag
attributes map[string]string // attributes will be like map[name]value attributes map[string]string // attributes will be like map[name]value
last_attribute string last_attribute string
parent &Tag = unsafe { 0 } parent &Tag = unsafe { nil }
position_in_parent int position_in_parent int
closed bool closed bool
close_type CloseTagType = .in_name close_type CloseTagType = .in_name

View File

@ -6,8 +6,8 @@ import time
// SSLConn is the current connection // SSLConn is the current connection
pub struct SSLConn { pub struct SSLConn {
mut: mut:
sslctx &C.SSL_CTX sslctx &C.SSL_CTX = unsafe { nil }
ssl &C.SSL ssl &C.SSL = unsafe { nil }
handle int handle int
duration time.Duration duration time.Duration
} }

View File

@ -32,7 +32,7 @@ pub enum BodyType {
pub struct Client { pub struct Client {
mut: mut:
conn net.TcpConn conn net.TcpConn
ssl_conn &openssl.SSLConn = unsafe { 0 } ssl_conn &openssl.SSLConn = unsafe { nil }
reader io.BufferedReader reader io.BufferedReader
pub: pub:
server string server string

View File

@ -324,7 +324,7 @@ pub struct URL {
pub mut: pub mut:
scheme string scheme string
opaque string // encoded opaque data 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 host string // host or host:port
path string // path (relative paths may omit leading slash) path string // path (relative paths may omit leading slash)
raw_path string // encoded path hint (see escaped_path method) 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 { struct ParseAuthorityRes {
user &Userinfo user &Userinfo = unsafe { nil }
host string host string
} }

View File

@ -19,7 +19,7 @@ const (
pub struct Client { pub struct Client {
is_server bool is_server bool
mut: 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 flags []Flag // flags used in handshake
fragments []Fragment // current fragments fragments []Fragment // current fragments
message_callbacks []MessageEventHandler // all callbacks on_message message_callbacks []MessageEventHandler // all callbacks on_message
@ -34,11 +34,11 @@ pub:
write_timeout i64 write_timeout i64
pub mut: pub mut:
header http.Header // headers that will be passed when connecting 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 nonce_size int = 16 // size of nounce used for masking
panic_on_callback bool // set to true of callbacks can panic panic_on_callback bool // set to true of callbacks can panic
state State // current state of connection 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 resource_name string // name of current resource
last_pong_ut i64 // last time in unix time we got a pong message last_pong_ut i64 // last time in unix time we got a pong message
} }

View File

@ -9,8 +9,8 @@ import rand
// Server represents a websocket server connection // Server represents a websocket server connection
pub struct Server { pub struct Server {
mut: mut:
logger &log.Logger // logger used to log logger &log.Logger = unsafe { nil } // logger used to log
ls &net.TcpListener // listener used to get incoming connection to socket ls &net.TcpListener = unsafe { nil } // listener used to get incoming connection to socket
accept_client_callbacks []AcceptClientFn // accept client callback functions accept_client_callbacks []AcceptClientFn // accept client callback functions
message_callbacks []MessageEventHandler // new message callback functions message_callbacks []MessageEventHandler // new message callback functions
close_callbacks []CloseEventHandler // close message callback functions close_callbacks []CloseEventHandler // close message callback functions
@ -30,8 +30,8 @@ pub:
resource_name string // resource that the client access resource_name string // resource that the client access
client_key string // unique key of client client_key string // unique key of client
pub mut: pub mut:
server &Server server &Server = unsafe { nil }
client &Client client &Client = unsafe { nil }
} }
[params] [params]

View File

@ -14,7 +14,7 @@ pub enum AssetMode {
// See https://developer.android.com/ndk/reference/struct/a-native-activity for more info. // See https://developer.android.com/ndk/reference/struct/a-native-activity for more info.
struct C.ANativeActivity { struct C.ANativeActivity {
pub: 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. clazz voidptr // (jobject) The NativeActivity object handle.
env voidptr // (JNIEnv *) JNI context for the main thread of the app. env voidptr // (JNIEnv *) JNI context for the main thread of the app.
externalDataPath &char // Path to this application's external (removable/mountable) data directory. externalDataPath &char // Path to this application's external (removable/mountable) data directory.

View File

@ -63,9 +63,9 @@ mut:
struct StartupInfo { struct StartupInfo {
mut: mut:
cb u32 cb u32
lp_reserved &u16 lp_reserved &u16 = unsafe { nil }
lp_desktop &u16 lp_desktop &u16 = unsafe { nil }
lp_title &u16 lp_title &u16 = unsafe { nil }
dw_x u32 dw_x u32
dw_y u32 dw_y u32
dw_x_size u32 dw_x_size u32
@ -76,7 +76,7 @@ mut:
dw_flags u32 dw_flags u32
w_show_window u16 w_show_window u16
cb_reserved2 u16 cb_reserved2 u16
lp_reserved2 &u8 lp_reserved2 &u8 = unsafe { nil }
h_std_input voidptr h_std_input voidptr
h_std_output voidptr h_std_output voidptr
h_std_error voidptr h_std_error voidptr
@ -428,7 +428,7 @@ pub:
// status_ constants // status_ constants
code u32 code u32
flags u32 flags u32
record &ExceptionRecord record &ExceptionRecord = unsafe { nil }
address voidptr address voidptr
param_count u32 param_count u32
// params []voidptr // params []voidptr
@ -440,8 +440,8 @@ pub struct ContextRecord {
pub struct ExceptionPointers { pub struct ExceptionPointers {
pub: pub:
exception_record &ExceptionRecord exception_record &ExceptionRecord = unsafe { nil }
context_record &ContextRecord context_record &ContextRecord = unsafe { nil }
} }
pub type VectoredExceptionHandler = fn (&ExceptionPointers) u32 pub type VectoredExceptionHandler = fn (&ExceptionPointers) u32

View File

@ -48,13 +48,13 @@ pub struct WProcess {
pub mut: pub mut:
proc_info ProcessInformation proc_info ProcessInformation
command_line [65536]u8 command_line [65536]u8
child_stdin &u32 child_stdin &u32 = unsafe { nil }
// //
child_stdout_read &u32 child_stdout_read &u32 = unsafe { nil }
child_stdout_write &u32 child_stdout_write &u32 = unsafe { nil }
// //
child_stderr_read &u32 child_stderr_read &u32 = unsafe { nil }
child_stderr_write &u32 child_stderr_write &u32 = unsafe { nil }
} }
fn (mut p Process) win_spawn_process() int { fn (mut p Process) win_spawn_process() int {

View File

@ -18,7 +18,7 @@ import io
pub struct DB { pub struct DB {
mut: mut:
conn &C.PGconn conn &C.PGconn = unsafe { nil }
} }
pub struct Row { pub struct Row {

View File

@ -63,17 +63,17 @@ pub:
} }
struct Picoev { struct Picoev {
loop &C.picoev_loop loop &C.picoev_loop = unsafe { nil }
cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response) cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response)
err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError) err_cb fn (voidptr, picohttpparser.Request, mut picohttpparser.Response, IError)
user_data voidptr user_data voidptr
timeout_secs int timeout_secs int
max_headers int max_headers int
mut: mut:
date &u8 date &u8 = unsafe { nil }
buf &u8 buf &u8 = unsafe { nil }
idx [1024]int idx [1024]int
out &u8 out &u8 = unsafe { nil }
} }
[inline] [inline]

View File

@ -3,10 +3,10 @@ module picohttpparser
pub struct Response { pub struct Response {
fd int fd int
pub: pub:
date &u8 = unsafe { 0 } date &u8 = unsafe { nil }
buf_start &u8 = unsafe { 0 } buf_start &u8 = unsafe { nil }
pub mut: pub mut:
buf &u8 = unsafe { 0 } buf &u8 = unsafe { nil }
} }
[inline] [inline]

View File

@ -6,7 +6,7 @@ pub struct Screenshot {
height int height int
size int size int
mut: mut:
pixels &u8 pixels &u8 = unsafe { nil }
} }
[manualfree] [manualfree]

View File

@ -43,8 +43,8 @@ struct C.sqlite3_stmt {
[heap] [heap]
struct Stmt { struct Stmt {
stmt &C.sqlite3_stmt stmt &C.sqlite3_stmt = unsafe { nil }
db &DB db &DB = unsafe { nil }
} }
struct SQLError { struct SQLError {
@ -57,7 +57,7 @@ pub struct DB {
pub mut: pub mut:
is_open bool is_open bool
mut: mut:
conn &C.sqlite3 conn &C.sqlite3 = unsafe { nil }
} }
pub fn (db &DB) str() string { pub fn (db &DB) str() string {

View File

@ -21,9 +21,9 @@ enum BufferElemStat {
struct Subscription { struct Subscription {
mut: mut:
sem &Semaphore sem &Semaphore = unsafe { nil }
prev &&Subscription prev &&Subscription = unsafe { nil }
nxt &Subscription nxt &Subscription = unsafe { nil }
} }
enum Direction { enum Direction {
@ -32,8 +32,8 @@ enum Direction {
} }
pub struct Channel { pub struct Channel {
ringbuf &u8 // queue for buffered channels ringbuf &u8 = unsafe { nil } // queue for buffered channels
statusbuf &u8 // flags to synchronize write/read in ringbuf statusbuf &u8 = unsafe { nil } // flags to synchronize write/read in ringbuf
objsize u32 objsize u32
mut: // atomic mut: // atomic
writesem Semaphore // to wake thread that wanted to write, but buffer was full 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_write_idx u32
buf_elem_read_idx u32 buf_elem_read_idx u32
// for select // for select
write_subscriber &Subscription write_subscriber &Subscription = unsafe { nil }
read_subscriber &Subscription read_subscriber &Subscription = unsafe { nil }
write_sub_mtx u16 write_sub_mtx u16
read_sub_mtx u16 read_sub_mtx u16
closed u16 closed u16

View File

@ -19,7 +19,7 @@ const utf8_max = 0x10FFFF
// Checker checks a tree of TOML `ast.Value`'s for common errors. // Checker checks a tree of TOML `ast.Value`'s for common errors.
pub struct Checker { pub struct Checker {
scanner &scanner.Scanner scanner &scanner.Scanner = unsafe { nil }
} }
// check checks the `ast.Value` and all it's children // check checks the `ast.Value` and all it's children

View File

@ -16,7 +16,7 @@ const (
// Decoder decode special sequences in a tree of TOML `ast.Value`'s. // Decoder decode special sequences in a tree of TOML `ast.Value`'s.
pub struct Decoder { pub struct Decoder {
scanner &scanner.Scanner scanner &scanner.Scanner = unsafe { nil }
} }
// decode decodes certain `ast.Value`'s and all it's children. // decode decodes certain `ast.Value`'s and all it's children.

View File

@ -51,7 +51,7 @@ pub struct Parser {
pub: pub:
config Config config Config
mut: mut:
scanner &scanner.Scanner scanner &scanner.Scanner = unsafe { nil }
prev_tok token.Token prev_tok token.Token
tok token.Token tok token.Token
peek_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`. // `decode_values` is used to en- or disable decoding of values with the `decoder.Decoder`.
pub struct Config { pub struct Config {
pub: pub:
scanner &scanner.Scanner scanner &scanner.Scanner = unsafe { nil }
run_checks bool = true run_checks bool = true
decode_values bool = true decode_values bool = true
} }

View File

@ -66,7 +66,7 @@ pub:
// A document can be constructed from a `string` buffer or from a file path // A document can be constructed from a `string` buffer or from a file path
pub struct Doc { pub struct Doc {
pub: pub:
ast &ast.Root ast &ast.Root = unsafe { nil }
} }
// parse_file parses the TOML file in `path`. // parse_file parses the TOML file in `path`.

View File

@ -261,7 +261,7 @@ pub mut:
typ Type // type of the entire thing (`Foo.bar`) typ Type // type of the entire thing (`Foo.bar`)
name_type Type // T in `T.name` or typeof in `typeof(expr).name` 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 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 from_embed_types []Type // holds the type of the embed that the method is called from
has_hidden_receiver bool 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` 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 next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl
// //
source_file &File = unsafe { 0 } source_file &File = unsafe { nil }
scope &Scope scope &Scope = unsafe { nil }
label_names []string label_names []string
pos token.Pos // function declaration position pos token.Pos // function declaration position
} }
@ -598,7 +598,7 @@ pub mut:
concrete_list_pos token.Pos concrete_list_pos token.Pos
raw_concrete_types []Type raw_concrete_types []Type
free_receiver bool // true if the receiver expression needs to be freed 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 from_embed_types []Type // holds the type of the embed that the method is called from
comments []Comment comments []Comment
} }
@ -730,7 +730,7 @@ pub:
nr_lines int // number of source code lines in the file (including newlines and comments) nr_lines int // number of source code lines in the file (including newlines and comments)
nr_bytes int // number of processed source code bytes nr_bytes int // number of processed source code bytes
mod Module // the module of the source file (from `module xyz` at the top) 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_test bool // true for _test.v files
is_generated bool // true for `[generated] module xyz` files; turn off notices 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 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 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 string // absolute path of the source file - '/projects/v/file.v'
path_base string // file name - 'file.v' (useful for tracing) 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 stmts []Stmt // all the statements in the source file
imports []Import // all the imports imports []Import // all the imports
auto_imports []string // imports that were implicitely added auto_imports []string // imports that were implicitely added
@ -808,7 +808,7 @@ pub:
mut_pos token.Pos mut_pos token.Pos
comptime bool comptime bool
pub mut: pub mut:
scope &Scope scope &Scope = unsafe { nil }
obj ScopeObject obj ScopeObject
mod string mod string
name string name string
@ -932,7 +932,7 @@ pub mut:
cond Expr cond Expr
pkg_exist bool pkg_exist bool
stmts []Stmt stmts []Stmt
scope &Scope scope &Scope = unsafe { nil }
} }
pub struct UnsafeExpr { pub struct UnsafeExpr {
@ -952,7 +952,7 @@ pub mut:
comments []Comment comments []Comment
is_expr bool is_expr bool
typ Type typ Type
scope &Scope scope &Scope = unsafe { nil }
} }
[minify] [minify]
@ -981,7 +981,7 @@ pub:
pub mut: pub mut:
stmts []Stmt // right side stmts []Stmt // right side
exprs []Expr // left side exprs []Expr // left side
scope &Scope scope &Scope = unsafe { nil }
} }
pub struct SelectExpr { pub struct SelectExpr {
@ -1033,7 +1033,7 @@ pub mut:
cond Expr cond Expr
stmts []Stmt stmts []Stmt
label string // `label: for {` label string // `label: for {`
scope &Scope scope &Scope = unsafe { nil }
} }
[minify] [minify]
@ -1056,7 +1056,7 @@ pub mut:
high_type Type high_type Type
kind Kind // array/map/string kind Kind // array/map/string
label string // `label: for {` label string // `label: for {`
scope &Scope scope &Scope = unsafe { nil }
} }
pub struct ForCStmt { pub struct ForCStmt {
@ -1072,7 +1072,7 @@ pub mut:
inc Stmt // i++; i += 2 inc Stmt // i++; i += 2
stmts []Stmt stmts []Stmt
label string // `label: for {` label string // `label: for {`
scope &Scope scope &Scope = unsafe { nil }
} }
// #include, #define etc // #include, #define etc
@ -1338,7 +1338,7 @@ pub:
pos token.Pos pos token.Pos
pub mut: pub mut:
templates []AsmTemplate templates []AsmTemplate
scope &Scope scope &Scope = unsafe { nil }
output []AsmIO output []AsmIO
input []AsmIO input []AsmIO
global_labels []string // labels defined in assembly block, exported with `.globl` global_labels []string // labels defined in assembly block, exported with `.globl`
@ -1573,7 +1573,7 @@ pub:
pub mut: pub mut:
exprs []Expr exprs []Expr
typ Type typ Type
scope &Scope scope &Scope = unsafe { nil }
} }
pub struct SizeOf { pub struct SizeOf {
@ -1674,7 +1674,7 @@ pub:
has_parens bool // if $() is used, for vfmt has_parens bool // if $() is used, for vfmt
method_name string method_name string
method_pos token.Pos method_pos token.Pos
scope &Scope scope &Scope = unsafe { nil }
left Expr left Expr
args_var string args_var string
// //

View File

@ -9,7 +9,7 @@ pub mut:
// mut: // mut:
objects map[string]ScopeObject objects map[string]ScopeObject
struct_fields map[string]ScopeStructField struct_fields map[string]ScopeStructField
parent &Scope parent &Scope = unsafe { nil }
detached_from_parent bool detached_from_parent bool
children []&Scope children []&Scope
start_pos int start_pos int

View File

@ -20,7 +20,7 @@ pub mut:
dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions
imports []string // List of all imports imports []string // List of all imports
modules []string // Topologically sorted list of all modules registered by the application modules []string // Topologically sorted list of all modules registered by the application
global_scope &Scope global_scope &Scope = unsafe { nil }
cflags []cflag.CFlag cflags []cflag.CFlag
redefined_fns []string redefined_fns []string
fn_generic_types map[string][][]Type // for generic functions fn_generic_types map[string][][]Type // for generic functions
@ -35,7 +35,7 @@ pub mut:
panic_handler FnPanicHandler = default_table_panic_handler panic_handler FnPanicHandler = default_table_panic_handler
panic_userdata voidptr = unsafe { nil } // can be used to pass arbitrary data to panic_handler; panic_userdata voidptr = unsafe { nil } // can be used to pass arbitrary data to panic_handler;
panic_npanics int 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. <int, string> cur_concrete_types []Type // current concrete types, e.g. <int, string>
gostmts int // how many `go` statements there were in the parsed files. 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 {` // When table.gostmts > 0, __VTHREADS__ is defined, which can be checked with `$if threads {`

View File

@ -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 .` 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 module_path string
pub mut: pub mut:
checker &checker.Checker checker &checker.Checker = unsafe { nil }
transformer &transformer.Transformer transformer &transformer.Transformer = unsafe { nil }
out_name_c string out_name_c string
out_name_js string out_name_js string
stats_lines int // size of backend generated source code in lines 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_errors int // accumulated error count of scanner, parser, checker, and builder
nr_warnings int // accumulated warning 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 nr_notices int // accumulated notice count of scanner, parser, checker, and builder
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
module_search_paths []string module_search_paths []string
parsed_files []&ast.File parsed_files []&ast.File
//$if windows { //$if windows {
cached_msvc MsvcResult cached_msvc MsvcResult
//} //}
table &ast.Table table &ast.Table = unsafe { nil }
ccoptions CcompilerOptions ccoptions CcompilerOptions
// //
// Note: changes in mod `builtin` force invalidation of every other .v file // Note: changes in mod `builtin` force invalidation of every other .v file

View File

@ -25,11 +25,11 @@ pub fn show(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.File)
struct Mapper { struct Mapper {
pos int pos int
mut: mut:
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
table &ast.Table table &ast.Table = unsafe { nil }
file &ast.File = unsafe { 0 } file &ast.File = unsafe { nil }
node &ast.Node = unsafe { 0 } node &ast.Node = unsafe { nil }
fn_decl &ast.FnDecl = unsafe { 0 } fn_decl &ast.FnDecl = unsafe { nil }
caller_name string caller_name string
dot_caller_name string dot_caller_name string
is_caller_used bool is_caller_used bool

View File

@ -56,10 +56,10 @@ fn all_valid_comptime_idents() []string {
[heap; minify] [heap; minify]
pub struct Checker { pub struct Checker {
pref &pref.Preferences // Preferences shared from V struct pref &pref.Preferences = unsafe { nil } // Preferences shared from V struct
pub mut: pub mut:
table &ast.Table table &ast.Table = unsafe { nil }
file &ast.File = unsafe { 0 } file &ast.File = unsafe { nil }
nr_errors int nr_errors int
nr_warnings int nr_warnings int
nr_notices int nr_notices int

View File

@ -541,6 +541,13 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
node.pos) 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 {} else {}
@ -565,3 +572,27 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
} }
return node.typ 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)
}
}
}

View File

@ -1,5 +1,12 @@
vlib/v/checker/tests/reference_field_must_be_initialized.vv:8:7: error: reference field `Node.next` must be initialized vlib/v/checker/tests/reference_field_must_be_initialized.vv:8:7: warning: reference field `Node.next.next` must be initialized
6 | 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 |
7 | fn main(){ 7 | fn main(){
8 | n := Node{ data: 123 } 8 | n := Node{ data: 123 }
| ~~~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~~~

View File

@ -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 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{ 16 | animal.duck = Duck{
17 | age: animal.ageee 17 | age: animal.ageee
| ~~~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~~~

View File

@ -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 | }

View File

@ -0,0 +1,13 @@
struct ContainsRef {
a &int = unsafe { nil }
b &int
}
struct Outer {
c ContainsRef
}
fn main() {
o := Outer{}
dump(o)
}

View File

@ -12,8 +12,8 @@ pub struct EmbedFileData {
apath string apath string
compression_type string compression_type string
mut: mut:
compressed &u8 compressed &u8 = unsafe { nil }
uncompressed &u8 uncompressed &u8 = unsafe { nil }
free_compressed bool free_compressed bool
free_uncompressed bool free_uncompressed bool
pub: pub:
@ -100,7 +100,7 @@ pub struct EmbedFileIndexEntry {
id int id int
path string path string
algo string algo string
data &u8 data &u8 = unsafe { nil }
} }
// find_index_entry_by_path is used internally by the V compiler: // find_index_entry_by_path is used internally by the V compiler:

View File

@ -21,7 +21,7 @@ type Symbol = Object | ast.EmptyStmt | ast.FnDecl
pub struct Eval { pub struct Eval {
pref &pref.Preferences pref &pref.Preferences
pub mut: pub mut:
table &ast.Table table &ast.Table = unsafe { nil }
mods map[string]map[string]Symbol mods map[string]map[string]Symbol
future_register_consts map[string]map[string]map[string]ast.ConstField // mod:file:name:field future_register_consts map[string]map[string]map[string]ast.ConstField // mod:file:name:field
local_vars map[string]Var local_vars map[string]Var

View File

@ -141,7 +141,7 @@ pub mut:
} }
pub struct Ptr { pub struct Ptr {
val &Object val &Object = unsafe { nil }
} }
// override the autogenerated str, since it does not work // override the autogenerated str, since it does not work

View File

@ -18,8 +18,8 @@ const (
pub struct Fmt { pub struct Fmt {
pub mut: pub mut:
file ast.File file ast.File
table &ast.Table table &ast.Table = unsafe { nil }
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
is_debug bool is_debug bool
out strings.Builder out strings.Builder
out_imports strings.Builder out_imports strings.Builder

View File

@ -44,11 +44,11 @@ fn string_array_to_map(a []string) map[string]bool {
} }
pub struct Gen { pub struct Gen {
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
field_data_type ast.Type // cache her to avoid map lookups field_data_type ast.Type // cache her to avoid map lookups
module_built string module_built string
timers_should_print bool timers_should_print bool
table &ast.Table table &ast.Table = unsafe { nil }
mut: mut:
out strings.Builder out strings.Builder
cheaders strings.Builder cheaders strings.Builder
@ -78,11 +78,11 @@ mut:
sql_buf strings.Builder // for writing exprs to args via `sqlite3_bind_int()` etc sql_buf strings.Builder // for writing exprs to args via `sqlite3_bind_int()` etc
global_const_defs map[string]GlobalConstDef global_const_defs map[string]GlobalConstDef
sorted_global_const_names []string 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`) 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 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_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 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 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 {...}` chan_push_optionals map[string]string // types for `ch <- x or {...}`
mtxs string // array of mutexes if the `lock` has multiple variables mtxs string // array of mutexes if the `lock` has multiple variables
labeled_loops map[string]&ast.Stmt 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 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_ternary int // ?: comma separated statements on a single line
inside_map_postfix bool // inside map++/-- postfix expr inside_map_postfix bool // inside map++/-- postfix expr
@ -208,7 +208,7 @@ mut:
// main_fn_decl_node ast.FnDecl // main_fn_decl_node ast.FnDecl
cur_mod ast.Module 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_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 cur_lock ast.LockExpr
autofree_methods map[int]bool autofree_methods map[int]bool
generated_free_methods map[int]bool generated_free_methods map[int]bool

View File

@ -17,8 +17,8 @@ const (
pub struct Gen { pub struct Gen {
pub mut: pub mut:
table &ast.Table table &ast.Table = unsafe { nil }
pref &pref.Preferences pref &pref.Preferences = unsafe { nil }
// is_debug bool // is_debug bool
out strings.Builder out strings.Builder
out_imports strings.Builder out_imports strings.Builder

View File

@ -46,13 +46,13 @@ mut:
struct JsGen { struct JsGen {
pref &pref.Preferences pref &pref.Preferences
mut: mut:
table &ast.Table table &ast.Table = unsafe { nil }
definitions strings.Builder definitions strings.Builder
ns &Namespace ns &Namespace = unsafe { nil }
namespaces map[string]&Namespace namespaces map[string]&Namespace
doc &JsDoc doc &JsDoc = unsafe { nil }
enable_doc bool enable_doc bool
file &ast.File file &ast.File = unsafe { nil }
tmp_count int tmp_count int
inside_ternary bool inside_ternary bool
inside_or bool inside_or bool
@ -65,9 +65,9 @@ mut:
is_test bool is_test bool
stmt_start_pos int stmt_start_pos int
defer_stmts []ast.DeferStmt 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 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 copy_types []StrType // types that need to be deep copied
generated_copy_fns []StrType generated_copy_fns []StrType
array_fn_definitions []string // array equality functions that have been defined array_fn_definitions []string // array equality functions that have been defined
@ -84,7 +84,7 @@ mut:
cast_stack []ast.Type cast_stack []ast.Type
call_stack []ast.CallExpr call_stack []ast.CallExpr
is_vlines_enabled bool // is it safe to generate #line directives when -g is passed 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 comptime_var_type_map map[string]ast.Type
defer_ifdef string defer_ifdef string
cur_concrete_types []ast.Type cur_concrete_types []ast.Type

View File

@ -4,7 +4,7 @@ import v.ast
struct JsDoc { struct JsDoc {
mut: mut:
gen &JsGen gen &JsGen = unsafe { nil }
} }
fn new_jsdoc(gen &JsGen) &JsDoc { fn new_jsdoc(gen &JsGen) &JsDoc {

View File

@ -5,11 +5,11 @@ import v.ast
struct Type { struct Type {
// typ is the original type // typ is the original type
typ ast.Type [required] typ ast.Type [required]
sym &ast.TypeSymbol [required] sym &ast.TypeSymbol [required] = unsafe { nil }
// unaliased is `typ` once aliased have been resolved // unaliased is `typ` once aliased have been resolved
// it may not contain informations such as flags and nr_muls // it may not contain informations such as flags and nr_muls
unaliased ast.Type [required] unaliased ast.Type [required]
unaliased_sym &ast.TypeSymbol [required] unaliased_sym &ast.TypeSymbol [required] = unsafe { nil }
} }
// unwrap returns the following variants of a type: // unwrap returns the following variants of a type:

View File

@ -5,7 +5,7 @@ import v.token
pub struct Amd64 { pub struct Amd64 {
mut: mut:
g &Gen g &Gen = unsafe { nil }
// arm64 specific stuff for code generation // arm64 specific stuff for code generation
is_16bit_aligned bool is_16bit_aligned bool
} }

Some files were not shown because too many files have changed in this diff Show More