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

parser: warn when fixed-size ArrayInit doesn't have trailing {}. (#6137)

This commit is contained in:
Nick Treleaven 2020-08-16 03:54:05 +01:00 committed by GitHub
parent a02593204f
commit bab5c21224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 28 deletions

View File

@ -301,7 +301,7 @@ struct Foooj {
}
fn test_fixed() {
mut nums := [4]int
mut nums := [4]int{}
//x := nums[1..3]
//assert x.len == 2
assert nums[0] == 0
@ -310,7 +310,7 @@ fn test_fixed() {
assert nums[3] == 0
nums[1] = 7
assert nums[1] == 7
nums2 := [5]int // c_n
nums2 := [5]int{} // c_n
assert nums2[c_n - 1] == 0
}

View File

@ -48,7 +48,7 @@ fn print_backtrace_skipping_top_frames(xskipframes int) bool {
// so there is no need to have their twins in builtin_windows.v
fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
$if macos {
buffer := [100]byteptr
buffer := [100]byteptr{}
nr_ptrs := C.backtrace(buffer, 100)
if nr_ptrs < 2 {
eprintln('C.backtrace returned less than 2 frames')
@ -61,7 +61,7 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
fn print_backtrace_skipping_top_frames_freebsd(skipframes int) bool {
$if freebsd {
buffer := [100]byteptr
buffer := [100]byteptr{}
nr_ptrs := C.backtrace(buffer, 100)
if nr_ptrs < 2 {
eprintln('C.backtrace returned less than 2 frames')
@ -87,7 +87,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
C.tcc_backtrace("Backtrace")
return false
}
buffer := [100]byteptr
buffer := [100]byteptr{}
nr_ptrs := C.backtrace(buffer, 100)
if nr_ptrs < 2 {
eprintln('C.backtrace returned less than 2 frames')
@ -111,7 +111,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
eprintln(sframe)
continue
}
buf := [1000]byte
buf := [1000]byte{}
mut output := ''
for C.fgets(charptr(buf), 1000, f) != 0 {
output += tos(byteptr(buf), vstrlen(byteptr(buf)))

View File

@ -86,7 +86,7 @@ fn print_backtrace_skipping_top_frames(skipframes int) bool {
fn print_backtrace_skipping_top_frames_msvc(skipframes int) bool {
$if msvc {
mut offset := u64(0)
backtraces := [100]voidptr
backtraces := [100]voidptr{}
sic := SymbolInfoContainer{}
mut si := &sic.syminfo
si.f_size_of_struct = sizeof(SymbolInfo) // Note: C.SYMBOL_INFO is 88

View File

@ -271,7 +271,7 @@ pub fn (n int) hex1() string {
[inline]
fn u64_to_hex(nn u64, len byte) string {
mut n := nn
mut buf := [256]byte
mut buf := [256]byte{}
buf[len] = `\0`
mut i := 0
for i=len-1; i>=0; i-- {
@ -289,7 +289,7 @@ fn u64_to_hex(nn u64, len byte) string {
[inline]
fn u64_to_hex_no_leading_zeros(nn u64, len byte) string {
mut n := nn
mut buf := [256]byte
mut buf := [256]byte{}
buf[len] = `\0`
mut i := 0
for i=len-1; i>=0; i-- {

View File

@ -130,7 +130,7 @@ pub fn (ctx &Context) text_width(s string) int {
if !ctx.font_inited {
return 0
}
mut buf := [4]f32
mut buf := [4]f32{}
C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf)
return int((buf[2] - buf[0]) / ctx.scale)
}
@ -139,7 +139,7 @@ pub fn (ctx &Context) text_height(s string) int {
if !ctx.font_inited {
return 0
}
mut buf := [4]f32
mut buf := [4]f32{}
C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf)
return int((buf[3] - buf[1]) / ctx.scale)
}
@ -148,7 +148,7 @@ pub fn (ctx &Context) text_size(s string) (int, int) {
if !ctx.font_inited {
return 0,0
}
mut buf := [4]f32
mut buf := [4]f32{}
C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf)
return int((buf[2] - buf[0]) / ctx.scale), int((buf[3] - buf[1]) / ctx.scale)
}

View File

@ -3,7 +3,7 @@ module net
fn C.gethostname() int
// hostname returns the host name reported by the kernel.
pub fn hostname() ?string {
mut name := [256]byte
mut name := [256]byte{}
// https://www.ietf.org/rfc/rfc1035.txt
// The host name is returned as a null-terminated string.
namebp := byteptr(name)

View File

@ -186,7 +186,7 @@ pub fn (s Socket) accept() ?Socket {
}
pub fn (s Socket) peer_ip() ?string {
buf := [44]byte
buf := [44]byte{}
peeraddr := C.sockaddr_in{}
speeraddr := sizeof(peeraddr)
ok := C.getpeername(s.sockfd, &C.sockaddr(&peeraddr), &speeraddr)
@ -327,7 +327,7 @@ pub fn (s Socket) write(str string) ?int {
// read_line - retrieves a line from the socket s (i.e. a string ended with \n)
pub fn (s Socket) read_line() string {
mut buf := [max_read]byte // where C.recv will store the network data
mut buf := [max_read]byte{} // where C.recv will store the network data
mut res := '' // The final result, including the ending \n.
for {
mut line := '' // The current line. Can be a partial without \n in it.
@ -373,7 +373,7 @@ pub fn (s Socket) read_line() string {
// TODO
pub fn (s Socket) read_all() string {
mut buf := [max_read]byte // where C.recv will store the network data
mut buf := [max_read]byte{} // where C.recv will store the network data
mut res := '' // The final result, including the ending \n.
for {
n := C.recv(s.sockfd, buf, max_read - 1, 0)

View File

@ -2,7 +2,7 @@ import net
fn start_socket_udp_server() {
bufsize := 1024
bytes := [1024]byte
bytes := [1024]byte{}
s := net.socket_udp() or { panic(err) }
s.bind( 9876 ) or { panic(err) }
println('Waiting for udp packets:')

View File

@ -89,7 +89,7 @@ pub fn cp(old, new string) ? {
C.close(fp_from)
return error_with_code('cp: failed to write to $new', int(fp_to))
}
mut buf := [1024]byte
mut buf := [1024]byte{}
mut count := 0
for {
// FIXME: use sizeof, bug: 'os__buf' undeclared

View File

@ -141,7 +141,7 @@ pub fn exec(cmd string) ?Result {
if isnil(f) {
return error('exec("$cmd") failed')
}
buf := [4096]byte
buf := [4096]byte{}
mut res := strings.new_builder(1024)
for C.fgets(charptr(buf), 4096, f) != 0 {
bufbp := byteptr(buf)

View File

@ -264,7 +264,7 @@ pub fn exec(cmd string) ?Result {
h_std_error: child_stdout_write
dw_flags: u32(C.STARTF_USESTDHANDLES)
}
command_line := [32768]u16
command_line := [32768]u16{}
C.ExpandEnvironmentStringsW(cmd.to_wide(), voidptr(&command_line), 32768)
create_process_ok := C.CreateProcessW(0, command_line, 0, 0, C.TRUE, 0, 0, 0, voidptr(&start_info), voidptr(&proc_info))
if !create_process_ok {
@ -274,7 +274,7 @@ pub fn exec(cmd string) ?Result {
}
C.CloseHandle(child_stdin)
C.CloseHandle(child_stdout_write)
buf := [4096]byte
buf := [4096]byte{}
mut bytes_read := u32(0)
mut read_data := strings.new_builder(1024)
for {

View File

@ -77,7 +77,7 @@ pub fn f64_to_str_lnd(f f64, dec_digit int) string {
m_sgn_flag := false
mut sgn := 1
mut b := [26]byte
mut b := [26]byte{}
mut d_pos := 1
mut i := 0
mut i1 := 0

View File

@ -242,7 +242,7 @@ pub fn f64_to_str_l(f f64) string {
m_sgn_flag := false
mut sgn := 1
mut b := [26]byte
mut b := [26]byte{}
mut d_pos := 1
mut i := 0
mut i1 := 0

View File

@ -71,9 +71,8 @@ fn (mut p Parser) array_init() ast.ArrayInit {
}
last_pos = p.tok.position()
p.check(.rcbr)
}
else {
// p.warn_with_pos('use e.g. `x := [1]Type{}` instead of `x := [1]Type`', last_pos)
} else {
p.warn_with_pos('use e.g. `x := [1]Type{}` instead of `x := [1]Type`', last_pos)
}
} else {
if p.tok.kind == .not {

View File

@ -23,7 +23,7 @@ pub const (
// vhash() returns the build string C.V_COMMIT_HASH . See cmd/tools/gen_vc.v .
pub fn vhash() string {
mut buf := [50]byte
mut buf := [50]byte{}
buf[0] = 0
unsafe {
C.snprintf(charptr(buf), 50, '%s', C.V_COMMIT_HASH)
@ -95,7 +95,7 @@ pub fn githash(should_get_from_filesystem bool) string {
}
break
}
mut buf := [50]byte
mut buf := [50]byte{}
buf[0] = 0
unsafe {
C.snprintf(charptr(buf), 50, '%s', C.V_CURRENT_COMMIT_HASH)