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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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() {

View File

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

View File

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

View File

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

View File

@ -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() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) {

View File

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

View File

@ -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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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`.

View File

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

View File

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

View File

@ -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. <int, string>
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 {`

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 .`
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

View File

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

View File

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

View File

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

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
6 |
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 |
7 | fn main(){
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
15 |
15 |
16 | animal.duck = Duck{
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
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:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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