breaking,checker: disallow initializing private struct fields outside structs module (#21183)

This commit is contained in:
Turiiya 2024-04-12 12:53:02 +02:00 committed by GitHub
parent a8d0cdd31b
commit 1a35a783f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
96 changed files with 225 additions and 111 deletions

View file

@ -41,7 +41,7 @@ jobs:
- name: Test vsql compilation and examples
run: |
echo "Install vsql"
.github/workflows/retry.sh v install elliotchance.vsql ; cd ~/.vmodules/elliotchance/vsql
.github/workflows/retry.sh v install https://github.com/ttytm/vsql@temp/vi-ci ; cd ~/.vmodules/vsql
echo "Generate vsql/grammar.v"
make vsql/grammar.v
echo "Compile vsql"
@ -53,10 +53,10 @@ jobs:
- name: Test discord.v
run: |
echo "Clone https://github.com/DarpHome/discord.v/"
.github/workflows/retry.sh git clone https://github.com/DarpHome/discord.v/ discord && cd discord
echo "Checkout last known good commit"
git checkout 533485c08f21df91ff62fea9477e7017d21f91c4
echo "Clone https://github.com/DarpHome/discord.v"
.github/workflows/retry.sh v install https://github.com/ttytm/discord.v@temp/v-ci && cd ~/.vmodules/discord
# echo "Checkout last known good commit"
# git checkout 789de8ad35ee2683fbcd950fc07936f052088d0c
echo "Execute Tests"
v test .

View file

@ -11,6 +11,7 @@ const max_parallel_workers = runtime.nr_jobs()
@[params]
pub struct ParserSettings {
pub:
sequential bool
img bool
extra_workers int

View file

@ -11,6 +11,7 @@ pub const default_gravity = 4.9
@[params]
pub struct SimParams {
pub:
rope_length f64 = sim.default_rope_length
bearing_mass f64 = sim.default_bearing_mass
magnet_spacing f64 = sim.default_magnet_spacing

View file

@ -1,7 +1,7 @@
module sim
pub struct SimState {
mut:
pub mut:
position Vector3D
velocity Vector3D
accel Vector3D

View file

@ -4,6 +4,7 @@ import math
// Vector3D is a 3D vector
pub struct Vector3D {
pub:
x f64
y f64
z f64

View file

@ -7,9 +7,9 @@ const max_iterations = 1000
const simulation_delta_t = 0.0005
pub struct SimRequest {
pub:
params SimParams
state SimState
pub:
id int
}

View file

@ -27,7 +27,7 @@ fn remap(v f64, min f64, max f64, new_min f64, new_max f64) f64 {
// Particle
pub struct Particle {
mut:
pub mut:
location vec.Vec2[f64]
velocity vec.Vec2[f64]
acceleration vec.Vec2[f64]

View file

@ -7,10 +7,12 @@ import rand
import sokol.sgl
pub struct SystemConfig {
pub:
pool int
}
pub struct System {
pub:
width int
height int
mut:

View file

@ -40,11 +40,9 @@ fn new_app() !&App {
}
fn new_websocker_server() !&websocket.Server {
mut wss := &websocket.Server{
logger: &log.Log{
level: .debug
}
}
mut logger := &log.Log{}
logger.set_level(.debug)
mut wss := websocket.new_server(.ip, 8080, '', logger: logger)
wss.on_connect(fn (mut server_client websocket.ServerClient) !bool {
slog('ws.on_connect, server_client.client_key: ${server_client.client_key}')
return true

View file

@ -182,6 +182,7 @@ pub fn chunk[T](array []T, size int) [][]T {
}
pub struct WindowAttribute {
pub:
size int
step int = 1
}

View file

@ -153,6 +153,7 @@ pub fn (mut b Benchmark) record_measure(label string) i64 {
// If it is set, the preparation time (compile time) will be shown before the measured runtime.
@[params]
pub struct MessageOptions {
pub:
preparation time.Duration // the duration of the preparation time for the step
}

View file

@ -25,21 +25,6 @@ fn test_if_string_flag_parses() {
flag.parse(['-flag=value2'], false) or { panic(err) }
mut values := flag.get_strings() or { panic(err) }
assert values == ['value1', 'value2']
flags := [
cli.Flag{
flag: .string_array
name: 'flag'
value: ['a', 'b', 'c']
},
cli.Flag{
flag: .string
name: 'flag2'
},
]
values = flags.get_strings('flag') or { panic(err) }
assert values == ['a', 'b', 'c']
}
fn test_if_bool_flag_parses() {
@ -94,21 +79,6 @@ fn test_if_int_flag_parses() {
flag.parse(['-flag=45'], false) or { panic(err) }
mut values := flag.get_ints() or { panic(err) }
assert values == [42, 45]
flags := [
cli.Flag{
flag: .int_array
name: 'flag'
value: ['1', '2', '3']
},
cli.Flag{
flag: .int
name: 'flag2'
},
]
values = flags.get_ints('flag') or { panic(err) }
assert values == [1, 2, 3]
}
fn test_if_float_flag_parses() {
@ -139,21 +109,6 @@ fn test_if_float_flag_parses() {
flag.parse(['-flag=1.3'], false) or { panic(err) }
mut values := flag.get_floats() or { panic(err) }
assert values == [3.1, 1.3]
flags := [
cli.Flag{
flag: .float_array
name: 'flag'
value: ['1.1', '2.2', '3.3']
},
cli.Flag{
flag: .float
name: 'flag2'
},
]
values = flags.get_floats('flag') or { panic(err) }
assert values == [1.1, 2.2, 3.3]
}
fn test_if_flag_parses_with_abbrev() {

View file

@ -42,6 +42,7 @@ pub fn compress(data []u8) ![]u8 {
@[params]
pub struct DecompressParams {
pub:
verify_header_checksum bool = true
verify_length bool = true
verify_checksum bool = true

View file

@ -7,6 +7,7 @@ import os
@[params]
pub struct ZipFolderOptions {
pub:
omit_empty_folders bool
}

View file

@ -390,6 +390,7 @@ pub fn default_c_level() int {
@[params]
pub struct CompressParams {
pub:
compression_level int // 1~22
nb_threads int = 1 // how many threads will be spawned to compress in parallel
checksum_flag bool = true
@ -422,6 +423,7 @@ pub fn compress(data []u8, params CompressParams) ![]u8 {
@[params]
pub struct DecompressParams {
pub:
window_log_max int
}

View file

@ -53,6 +53,7 @@ mut:
// DynamicLibLoaderConfig is a configuration for DynamicLibLoader.
@[params]
pub struct DynamicLibLoaderConfig {
pub:
// flags is the flags for dlopen.
flags int = dl.rtld_lazy
// key is the key to register the DynamicLibLoader.

View file

@ -205,6 +205,7 @@ fn overhead_for(c &Chunk) usize {
//
// Why not `interface?` Interfaces require memory allocation so it is simpler to pass a struct.
pub struct Allocator {
pub:
alloc fn (voidptr, usize) (voidptr, usize, u32) = unsafe { nil }
remap fn (voidptr, voidptr, usize, usize, bool) voidptr = unsafe { nil }
free_part fn (voidptr, voidptr, usize, usize) bool = unsafe { nil }

View file

@ -42,6 +42,7 @@ Using these structs, it is possible to change the behavior of the CSV Reader.
The config struct is as follows:
```v ignore
pub struct SequentialReaderConfig {
pub:
scr_buf voidptr // pointer to the buffer of data
scr_buf_len i64 // if > 0 use the RAM pointed by scr_buf as source of data
file_path string
@ -128,6 +129,7 @@ Using these structs, it is possible to change the behavior of the CSV Reader.
The config struct is as follows:
```v ignore
pub struct RandomAccessReaderConfig {
pub:
scr_buf voidptr // pointer to the buffer of data
scr_buf_len i64 // if > 0 use the RAM pointed from scr_buf as source of data
file_path string

View file

@ -80,6 +80,7 @@ pub mut:
@[params]
pub struct RandomAccessReaderConfig {
pub:
scr_buf voidptr // pointer to the buffer of data
scr_buf_len i64 // if > 0 use the RAM pointed from scr_buf as source of data
file_path string
@ -344,6 +345,7 @@ pub fn (mut cr RandomAccessReader) get_row(y int) ![]string {
@[params]
pub struct GetCellConfig {
pub:
x int
y int
}
@ -444,6 +446,7 @@ pub fn (mut cr RandomAccessReader) get_cellt(cfg GetCellConfig) !CellValue {
******************************************************************************/
@[params]
pub struct GetHeaderConf {
pub:
header_row int // row where to inspect the header
}

View file

@ -13,6 +13,7 @@ import os
@[params]
pub struct SequentialReaderConfig {
pub:
scr_buf voidptr // pointer to the buffer of data
scr_buf_len i64 // if > 0 use the RAM pointed by scr_buf as source of data
file_path string

View file

@ -52,6 +52,7 @@ mut:
@[params]
pub struct ReaderConfig {
pub:
delimiter u8 = `,`
comment u8 = `#`
}

View file

@ -14,6 +14,7 @@ mut:
@[params]
pub struct WriterConfig {
pub:
use_crlf bool
delimiter u8 = `,`
}

View file

@ -5,12 +5,14 @@ import strconv
@[params]
pub struct EscapeConfig {
pub:
quote bool = true
}
@[params]
pub struct UnescapeConfig {
EscapeConfig
pub:
all bool
}

View file

@ -20,6 +20,7 @@ pub const default_entities_reverse = {
@[params]
pub struct EscapeConfig {
pub:
reverse_entities map[string]string = xml.default_entities_reverse
}
@ -38,6 +39,7 @@ pub fn escape_text(content string, config EscapeConfig) string {
@[params]
pub struct UnescapeConfig {
pub:
entities map[string]string = xml.default_entities
}

View file

@ -37,21 +37,25 @@ pub:
pub type DTDListItem = DTDElement | DTDEntity
pub struct DTDEntity {
pub:
name string @[required]
value string @[required]
}
pub struct DTDElement {
pub:
name string @[required]
definition []string @[required]
}
pub struct DocumentTypeDefinition {
pub:
name string
list []DTDListItem
}
pub struct DocumentType {
pub:
name string @[required]
dtd DTDInfo
}

View file

@ -226,6 +226,7 @@ pub enum PaintStyle {
@[params]
pub struct DrawRectParams {
pub:
x f32
y f32
w f32

View file

@ -545,6 +545,7 @@ pub enum EndEnum {
@[params]
pub struct EndOptions {
pub:
how EndEnum
}

View file

@ -270,6 +270,7 @@ pub fn (mut ctx Context) create_image_from_byte_array(b []u8) !Image {
}
pub struct StreamingImageConfig {
pub:
pixel_format gfx.PixelFormat = .rgba8
wrap_u gfx.Wrap = .clamp_to_edge
wrap_v gfx.Wrap = .clamp_to_edge

View file

@ -166,6 +166,7 @@ pub fn (ctx &Context) set_text_cfg(cfg gx.TextCfg) {
@[params]
pub struct DrawTextParams {
pub:
x int
y int
text string

View file

@ -16,6 +16,7 @@ pub mut:
// BufferedReaderConfig are options that can be given to a buffered reader.
pub struct BufferedReaderConfig {
pub:
reader Reader
cap int = 128 * 1024 // large for fast reading of big(ish) files
retries int = 2 // how many times to retry before assuming the stream ended

View file

@ -35,8 +35,8 @@ pub const read_all_grow_len = 1024
// ReadAllConfig allows options to be passed for the behaviour
// of read_all.
pub struct ReadAllConfig {
pub:
read_to_end_of_stream bool
mut:
reader Reader
}

View file

@ -5,6 +5,7 @@ import strings
@[params]
pub struct StringReaderParams {
pub:
// the reader interface
reader ?io.Reader
// initialize the builder with this source string

View file

@ -7,6 +7,7 @@ const retries = 10000
@[params]
pub struct TempFileOptions {
pub:
path string = os.temp_dir()
pattern string
}
@ -40,6 +41,7 @@ pub fn temp_file(tfo TempFileOptions) !(os.File, string) {
@[params]
pub struct TempDirOptions {
pub:
path string = os.temp_dir()
pattern string
}

View file

@ -49,9 +49,8 @@ fn test_set_always_flush() {
os.rmdir_all(lfolder) or {}
}
dump(lfolder)
mut l := log.Log{
level: .info
}
mut l := log.Log{}
l.set_level(.info)
l.set_full_logpath(lpath1)
l.set_always_flush(true)
l.warn('one warning')

View file

@ -117,6 +117,7 @@ pub fn integer_from_u64(value u64) Integer {
@[params]
pub struct IntegerConfig {
pub:
signum int = 1
}

View file

@ -53,6 +53,7 @@ pub fn angle_diff(radian_a f64, radian_b f64) f64 {
@[params]
pub struct DigitParams {
pub:
base int = 10
reverse bool
}

View file

@ -26,6 +26,7 @@ pub enum ShutdownDirection {
@[params]
pub struct ShutdownConfig {
pub:
how ShutdownDirection = .read_and_write
}

View file

@ -23,6 +23,7 @@ mut:
@[params]
pub struct GetTagsOptions {
pub:
name string
}

View file

@ -15,9 +15,10 @@ pub const max_headers = 50
// Header represents the key-value pairs in an HTTP header
pub struct Header {
mut:
pub mut:
// data map[string][]string
data [max_headers]HeaderKV
mut:
cur_pos int
// map of lowercase header keys to their original keys
// in order of appearance
@ -352,6 +353,7 @@ pub fn (mut h Header) free() {
}
pub struct HeaderConfig {
pub:
key CommonHeader
value string
}
@ -490,6 +492,7 @@ pub fn (mut h Header) delete_custom(key string) {
@[params]
pub struct HeaderCoerceConfig {
pub:
canonicalize bool
}
@ -553,6 +556,7 @@ pub fn (h Header) contains(key CommonHeader) bool {
@[params]
pub struct HeaderQueryConfig {
pub:
exact bool
}
@ -666,6 +670,7 @@ pub fn (h Header) keys() []string {
@[params]
pub struct HeaderRenderConfig {
pub:
version Version
coerce bool
canonicalize bool

View file

@ -388,6 +388,7 @@ pub:
pub struct UnexpectedExtraAttributeError {
Error
pub:
attributes []string
}

View file

@ -117,6 +117,7 @@ pub fn (mut r Response) set_version(v Version) {
}
pub struct ResponseConfig {
pub:
version Version = .v1_1
status Status = .ok
header Header

View file

@ -32,8 +32,9 @@ struct SSLCerts {
// SSLConn is the current connection
pub struct SSLConn {
pub:
config SSLConnectConfig
mut:
pub mut:
server_fd C.mbedtls_net_context
ssl C.mbedtls_ssl_context
conf C.mbedtls_ssl_config
@ -215,6 +216,7 @@ pub fn (mut l SSLListener) accept() !&SSLConn {
@[params]
pub struct SSLConnectConfig {
pub:
verify string // the path to a rootca.pem file, containing trusted CA certificate(s)
cert string // the path to a cert.pem file, containing client certificate(s) for the request
cert_key string // the path to a key.pem file, containing private keys for the client certificate(s)

View file

@ -7,8 +7,9 @@ import os
// SSLConn is the current connection
pub struct SSLConn {
pub:
config SSLConnectConfig
mut:
pub mut:
sslctx &C.SSL_CTX = unsafe { nil }
ssl &C.SSL = unsafe { nil }
handle int
@ -19,6 +20,7 @@ mut:
@[params]
pub struct SSLConnectConfig {
pub:
verify string // the path to a rootca.pem file, containing trusted CA certificate(s)
cert string // the path to a cert.pem file, containing client certificate(s) for the request
cert_key string // the path to a key.pem file, containing private keys for the client certificate(s)

View file

@ -47,6 +47,7 @@ pub mut:
}
pub struct Mail {
pub:
from string
to string
cc string

View file

@ -10,7 +10,6 @@ pub const tcp_default_write_timeout = 30 * time.second
pub struct TcpConn {
pub mut:
sock TcpSocket
mut:
handle int
write_deadline time.Time
read_deadline time.Time
@ -313,7 +312,6 @@ pub fn (c TcpConn) str() string {
pub struct TcpListener {
pub mut:
sock TcpSocket
mut:
accept_timeout time.Duration
accept_deadline time.Time
is_blocking bool = true

View file

@ -224,6 +224,7 @@ mut:
@[params]
pub struct ListenOptions {
pub:
backlog int = 128
}

View file

@ -4,6 +4,15 @@ import rand
import crypto.sha1
import encoding.base64
import encoding.binary
import log
const default_logger = setup_default_logger()
fn setup_default_logger() &log.Log {
mut l := &log.Log{}
l.set_level(.info)
return l
}
// htonl64 converts payload length to header bits
fn htonl64(payload_len u64) []u8 {

View file

@ -43,9 +43,7 @@ pub mut:
panic_on_callback bool // set to true of callbacks can panic
client_state shared ClientState // current state of connection
// logger used to log messages
logger &log.Logger = &log.Logger(&log.Log{
level: .info
})
logger &log.Logger = default_logger
resource_name string // name of current resource
last_pong_ut i64 // last time in unix time we got a pong message
}
@ -84,11 +82,10 @@ pub enum OPCode {
@[params]
pub struct ClientOpt {
pub:
read_timeout i64 = 30 * time.second
write_timeout i64 = 30 * time.second
logger &log.Logger = &log.Logger(&log.Log{
level: .info
})
logger &log.Logger = default_logger
}
// new_client instance a new websocket client

View file

@ -17,9 +17,7 @@ pub mut:
// Server represents a websocket server connection
pub struct Server {
mut:
logger &log.Logger = &log.Logger(&log.Log{
level: .info
})
logger &log.Logger = default_logger
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
@ -44,9 +42,8 @@ pub mut:
@[params]
pub struct ServerOpt {
logger &log.Logger = &log.Logger(&log.Log{
level: .info
})
pub:
logger &log.Logger = default_logger
}
// new_server instance a new websocket server on provided port and route
@ -143,13 +140,13 @@ fn (mut s Server) serve_client(mut c Client) ! {
// handle_handshake use an existing connection to respond to the handshake for a given key
pub fn (mut s Server) handle_handshake(mut conn net.TcpConn, key string) !&ServerClient {
mut logger := &log.Log{}
logger.set_level(.debug)
mut c := &Client{
is_server: true
conn: conn
is_ssl: false
logger: &log.Log{
level: .debug
}
logger: logger
client_state: ClientState{
state: .open
}

View file

@ -75,6 +75,7 @@ pub fn fd_read(fd int, maxbytes int) (string, int) {
pub struct C.fd_set {}
pub struct C.timeval {
pub:
tv_sec u64
tv_usec u64
}

View file

@ -121,6 +121,7 @@ pub fn cp_all(src string, dst string, overwrite bool) ! {
@[params]
pub struct MvParams {
pub:
overwrite bool = true
}
@ -717,6 +718,7 @@ pub fn log(s string) {
@[params]
pub struct MkdirParams {
pub:
mode u32 = 0o777 // note that the actual mode is affected by the process's umask
}

View file

@ -20,7 +20,7 @@ struct Winsize {
// Readline is the key struct for reading and holding user input via a terminal.
// Example: import readline { Readline }
pub struct Readline {
mut:
pub mut:
is_raw bool
orig_termios termios.Termios // Linux
current []rune // Line being edited

View file

@ -83,6 +83,7 @@ pub mut:
// | num_packets | 64 | for push model only, number of packets in the backend ringbuffer |
@[typedef]
pub struct C.saudio_desc {
pub:
sample_rate int
num_channels int
buffer_frames int

View file

@ -29,6 +29,7 @@ fn empty_cb(mut p PoolProcessor, idx int, task_id int) voidptr {
}
pub struct PoolProcessorConfig {
pub:
maxjobs int
callback ThreadCB = empty_cb
}

View file

@ -9,6 +9,7 @@ import os
@[params]
pub struct ZipFolderOptions {
pub:
omit_empty_folders bool
}

View file

@ -183,6 +183,7 @@ pub mut:
}
pub struct Config {
pub:
user_data voidptr
init_fn ?fn (voidptr)
frame_fn ?fn (voidptr)

View file

@ -5,6 +5,7 @@ module time
@[params]
pub struct StopWatchOptions {
pub:
auto_start bool = true
}

View file

@ -7,6 +7,7 @@ module time
// C.timeval represents a C time value.
pub struct C.timeval {
pub:
tv_sec u64
tv_usec u64
}

View file

@ -42,7 +42,7 @@ pub fn (t Time) local() Time {
// in most systems, these are __quad_t, which is an i64
pub struct C.timespec {
mut:
pub mut:
tv_sec i64
tv_nsec i64
}

View file

@ -48,6 +48,7 @@ const start_local_time = local_as_unix_time()
// in most systems, these are __quad_t, which is an i64
pub struct C.timespec {
pub:
tv_sec i64
tv_nsec i64
}

View file

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

View file

@ -14,6 +14,7 @@ const utf8_max = 0x10FFFF
// Decoder decode special sequences in a tree of TOML `ast.Value`'s.
pub struct Decoder {
pub:
scanner &scanner.Scanner = unsafe { nil }
}

View file

@ -203,6 +203,7 @@ fn to_any[T](value T) Any {
// DateTime is the representation of an RFC 3339 datetime string.
pub struct DateTime {
pub:
datetime string
}
@ -213,6 +214,7 @@ pub fn (dt DateTime) str() string {
// Date is the representation of an RFC 3339 date-only string.
pub struct Date {
pub:
date string
}
@ -223,6 +225,7 @@ pub fn (d Date) str() string {
// Time is the representation of an RFC 3339 time-only string.
pub struct Time {
pub:
time string
}

View file

@ -289,6 +289,7 @@ pub fn (t &Table) find_method(s &TypeSymbol, name string) !Fn {
@[params]
pub struct GetEmbedsOptions {
pub:
preceding []Type
}

View file

@ -1512,6 +1512,7 @@ fn (t Table) shorten_user_defined_typenames(original_name string, import_aliases
@[minify]
pub struct FnSignatureOpts {
pub:
skip_receiver bool
type_only bool
}

View file

@ -740,7 +740,25 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
for i, mut field in fields {
if field.name in inited_fields {
if c.mod != type_sym.mod && field.is_deprecated {
if c.mod != type_sym.mod {
if !field.is_pub {
parts := type_sym.name.split('.')
for init_field in node.init_fields {
if field.name == init_field.name {
mod_type := if parts.len > 1 {
parts#[-2..].join('.')
} else {
parts.last()
}
c.add_error_detail('this will become an error after 2024-05-31')
c.warn('initalizing private field `${field.name}` of `${mod_type}`',
init_field.pos)
// c.error('cannot access private field `${field.name}` on `${mod_type}`', init_field.pos)
break
}
}
}
if field.is_deprecated {
for init_field in node.init_fields {
if field.name == init_field.name {
c.deprecate('field', field.name, field.attrs, init_field.pos)
@ -748,6 +766,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
}
}
}
}
continue
}
sym := c.table.sym(field.typ)

View file

@ -1,5 +1,17 @@
module amod
pub struct Xyz {}
pub struct Xyz {
pub:
x int
}
pub struct Bcg {}
pub struct Bcg {
x int
}
@[params]
pub struct FooParams {
bar string
}
pub fn foo(opts FooParams) {}

View file

@ -1,7 +1,7 @@
module point
pub struct Point {
mut:
pub mut:
x int
y int
}

View file

@ -0,0 +1,14 @@
vlib/v/checker/tests/struct_field_private_err.vv:8:2: warning: initalizing private field `x` of `amod.Bcg`
6 |
7 | _ := amod.Bcg{
8 | x: 0
| ~~~~
9 | }
10 |
Details: this will become an error after 2024-05-31
vlib/v/checker/tests/struct_field_private_err.vv:11:10: warning: initalizing private field `bar` of `amod.FooParams`
9 | }
10 |
11 | amod.foo(bar: 'bar')
| ~~~~~~~~~~
Details: this will become an error after 2024-05-31

View file

@ -0,0 +1,11 @@
import v.checker.tests.amod
_ := amod.Xyz{
x: 0
}
_ := amod.Bcg{
x: 0
}
amod.foo(bar: 'bar')

View file

@ -41,6 +41,7 @@ pub enum MouseButtons {
end_options := mod_doc.contents['EndOptions']
assert end_options.content == '@[params]
pub struct EndOptions {
pub:
how EndEnum
}'
assert end_options.attrs == {

View file

@ -35,6 +35,7 @@ pub fn (mut d DotGraph) finish() {
//
pub struct NewNodeConfig {
pub:
node_name string
should_highlight bool
tooltip string
@ -57,6 +58,7 @@ pub fn (mut d DotGraph) new_node(nlabel string, cfg NewNodeConfig) {
//
pub struct NewEdgeConfig {
pub:
should_highlight bool
ctx voidptr = unsafe { nil }
name2node_fn FnLabel2NodeName = node_name

View file

@ -51,6 +51,7 @@ pub fn (mut e Eval) run(expression string, args ...Object) ![]Object {
type Symbol = Object | ast.EmptyStmt | ast.FnDecl
pub struct Eval {
pub:
pref &pref.Preferences = unsafe { nil }
pub mut:
table &ast.Table = unsafe { nil }

View file

@ -16,6 +16,7 @@ mut:
@[params]
struct AddInfoConfig {
pub:
use_threshold bool
}

View file

@ -23,6 +23,7 @@ pub fn (mut f Fmt) attrs(attrs []ast.Attr) {
@[params]
pub struct AttrsOptions {
pub:
same_line bool
}

View file

@ -14,6 +14,7 @@ const bs = '\\'
@[minify]
pub struct Fmt {
pub:
pref &pref.Preferences = unsafe { nil }
pub mut:
file ast.File
@ -56,6 +57,7 @@ pub mut:
@[params]
pub struct FmtOptions {
pub:
source_text string
}
@ -167,6 +169,7 @@ pub fn (mut f Fmt) wrap_long_line(penalty_idx int, add_indent bool) bool {
@[params]
pub struct RemoveNewLineConfig {
pub:
imports_buffer bool // Work on f.out_imports instead of f.out
}

View file

@ -23,6 +23,7 @@ pub fn (mut f Gen) attrs(attrs []ast.Attr) {
@[params]
pub struct AttrsOptions {
pub:
inline bool
}

View file

@ -126,6 +126,7 @@ pub fn (mut f Gen) wrap_long_line(penalty_idx int, add_indent bool) bool {
@[params]
pub struct RemoveNewLineConfig {
pub:
imports_buffer bool // Work on f.out_imports instead of f.out
}

View file

@ -79,11 +79,13 @@ enum Amd64SetOp {
@[params]
struct AvailableAmd64Register {
pub:
available Amd64Register
}
@[params]
struct Amd64RegisterOption {
pub:
reg Amd64Register = Amd64Register.rax
ssereg Amd64SSERegister = Amd64SSERegister.xmm0
}

View file

@ -231,6 +231,7 @@ struct GlobalVar {}
@[params]
struct VarConfig {
pub:
offset i32 // offset from the variable
typ ast.Type // type of the value you want to process e.g. struct fields.
}

View file

@ -103,6 +103,7 @@ pub fn (mut p Pool) type_size(typ ast.Type) (int, int) {
@[params]
pub struct PoolOpts {
pub:
null_terminated bool = true
intern_strings bool = true
store_relocs bool = true

View file

@ -21,6 +21,7 @@ fn help_dir() string {
@[params]
pub struct ExitOptions {
pub:
exit_code int
}

View file

@ -21,6 +21,7 @@ const allowed_lock_prefix_ins = ['add', 'adc', 'and', 'btc', 'btr', 'bts', 'cmpx
@[minify]
pub struct Parser {
pub:
pref &pref.Preferences = unsafe { nil }
mut:
file_base string // "hello.v"
@ -32,7 +33,6 @@ mut:
tok token.Token
prev_tok token.Token
peek_tok token.Token
table &ast.Table = unsafe { nil }
language ast.Language
fn_language ast.Language // .c for `fn C.abcd()` declarations
expr_level int // prevent too deep recursions for pathological programs
@ -80,7 +80,6 @@ mut:
is_translated bool // `[translated] module abc` - mark a file as translated, to relax some compiler checks for translated code.
attrs []ast.Attr // attributes before next decl stmt
expr_mod string // for constructing full type names in parse_type()
scope &ast.Scope = unsafe { nil }
imports map[string]string // alias => mod_name
ast_imports []ast.Import // mod_names
used_imports []string // alias
@ -107,6 +106,8 @@ mut:
script_mode_start_token token.Token
pub mut:
scanner &scanner.Scanner = unsafe { nil }
table &ast.Table = unsafe { nil }
scope &ast.Scope = unsafe { nil }
errors []errors.Error
warnings []errors.Warning
notices []errors.Notice
@ -647,6 +648,7 @@ fn (mut p Parser) check(expected token.Kind) {
@[params]
struct ParamsForUnexpected {
pub:
got string
expecting string
prepend_msg string
@ -929,6 +931,7 @@ fn (mut p Parser) comment_stmt() ast.ExprStmt {
@[params]
struct EatCommentsConfig {
pub:
same_line bool // Only eat comments on the same line as the previous token
follow_up bool // Comments directly below the previous token as long as there is no empty line
}
@ -4647,6 +4650,7 @@ fn (mut p Parser) trace[T](fbase string, x &T) {
@[params]
struct ParserShowParams {
pub:
msg string
reach int = 3
}

View file

@ -1,7 +1,7 @@
module newmodule
pub struct Params[T] {
mut:
pub mut:
a []T
b int
c T

View file

@ -1,7 +1,7 @@
module trace_calls
pub struct C.timespec {
mut:
pub mut:
tv_sec i64
tv_nsec i64
}

View file

@ -20,6 +20,7 @@ pub mut:
@[params]
pub struct TimerParams {
pub:
should_print bool
label string
}

View file

@ -4,6 +4,7 @@ import os
@[params]
pub struct FilterVTestConfig {
pub:
basepath string
fix_slashes bool = true
}

View file

@ -29,6 +29,7 @@ pub mut:
}
pub struct SSEMessage {
pub:
id string
event string
data string

View file

@ -321,6 +321,7 @@ pub fn (mut ctx Context) server_error(ecode int) Result {
@[params]
pub struct RedirectParams {
pub:
status_code int = 302
}
@ -523,6 +524,7 @@ pub fn run[T](global_app &T, port int) {
@[params]
pub struct RunParams {
pub:
family net.AddrFamily = .ip6 // use `family: .ip, host: 'localhost'` when you want it to bind only to 127.0.0.1
host string
port int = 8080
@ -1215,6 +1217,7 @@ fn (mut w Worker[T]) process_incoming_requests() {
@[params]
pub struct PoolParams[T] {
pub:
handler fn () T = unsafe { nil } @[required]
nr_workers int = runtime.nr_jobs()
}

View file

@ -8,6 +8,7 @@ import time
// Encoder encodes the an `Any` type into JSON representation.
// It provides parameters in order to change the end result.
pub struct Encoder {
pub:
newline u8
newline_spaces_count int
escape_unicode bool = true

View file

@ -16,6 +16,7 @@ pub enum KeyType {
}
pub struct StructCheckResult {
pub:
duplicates []string
superfluous []string
}

View file

@ -54,6 +54,7 @@ pub mut:
// CookieOptions contains the default settings for the cookie created in
// the `Sessions` struct.
pub struct CookieOptions {
pub:
cookie_name string = 'sid'
domain string
http_only bool = true

View file

@ -159,6 +159,7 @@ struct HtmlFileInfo {
// TemplateCacheParams are used to specify cache expiration delay and provide placeholder data for substitution in templates.
@[params]
pub struct TemplateCacheParams {
pub:
placeholders &map[string]DtmMultiTypeMap = &map[string]DtmMultiTypeMap{}
cache_delay_expiration i64 = dtm.cache_delay_expiration_by_default
}
@ -166,6 +167,7 @@ pub struct TemplateCacheParams {
// DynamicTemplateManagerInitialisationParams is used with 'initialize' function. (See below at initialize section)
@[params]
pub struct DynamicTemplateManagerInitialisationParams {
pub:
def_cache_path string
compress_html bool = true
active_cache_server bool = true

View file

@ -227,6 +227,7 @@ pub fn (mut ctx Context) server_error(msg string) Result {
@[params]
pub struct RedirectParams {
pub:
typ RedirectType
}

View file

@ -30,6 +30,7 @@ mut:
@[params]
pub struct MiddlewareOptions[T] {
pub:
handler fn (mut ctx T) bool @[required]
after bool
}

View file

@ -210,6 +210,7 @@ pub fn run[A, X](mut global_app A, port int) {
@[params]
pub struct RunParams {
pub:
// use `family: .ip, host: 'localhost'` when you want it to bind only to 127.0.0.1
family net.AddrFamily = .ip6
host string