Skip to content

Commit

Permalink
breaking,checker: disallow initializing private struct fields outside…
Browse files Browse the repository at this point in the history
… structs module (#21183)
  • Loading branch information
ttytm committed Apr 12, 2024
1 parent a8d0cdd commit 1a35a78
Show file tree
Hide file tree
Showing 96 changed files with 225 additions and 111 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/v_apps_and_modules_compile_ci.yml
Expand Up @@ -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"
Expand All @@ -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 .
Expand Down
1 change: 1 addition & 0 deletions examples/pendulum-simulation/modules/sim/args/parser.v
Expand Up @@ -11,6 +11,7 @@ const max_parallel_workers = runtime.nr_jobs()

@[params]
pub struct ParserSettings {
pub:
sequential bool
img bool
extra_workers int
Expand Down
1 change: 1 addition & 0 deletions examples/pendulum-simulation/modules/sim/params.v
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/pendulum-simulation/modules/sim/sim.v
@@ -1,7 +1,7 @@
module sim

pub struct SimState {
mut:
pub mut:
position Vector3D
velocity Vector3D
accel Vector3D
Expand Down
1 change: 1 addition & 0 deletions examples/pendulum-simulation/modules/sim/vec.v
Expand Up @@ -4,6 +4,7 @@ import math

// Vector3D is a 3D vector
pub struct Vector3D {
pub:
x f64
y f64
z f64
Expand Down
4 changes: 2 additions & 2 deletions examples/pendulum-simulation/modules/sim/worker.v
Expand Up @@ -7,10 +7,10 @@ const max_iterations = 1000
const simulation_delta_t = 0.0005

pub struct SimRequest {
pub:
params SimParams
state SimState
pub:
id int
id int
}

pub struct SimResult {
Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/particles/modules/particle/particle.v
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions examples/sokol/particles/modules/particle/system.v
Expand Up @@ -7,10 +7,12 @@ import rand
import sokol.sgl

pub struct SystemConfig {
pub:
pool int
}

pub struct System {
pub:
width int
height int
mut:
Expand Down
8 changes: 3 additions & 5 deletions examples/vweb/vweb_websocket/vweb_websocket.v
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vlib/arrays/arrays.v
Expand Up @@ -182,6 +182,7 @@ pub fn chunk[T](array []T, size int) [][]T {
}

pub struct WindowAttribute {
pub:
size int
step int = 1
}
Expand Down
1 change: 1 addition & 0 deletions vlib/benchmark/benchmark.v
Expand Up @@ -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
}

Expand Down
45 changes: 0 additions & 45 deletions vlib/cli/flag_test.v
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions vlib/compress/gzip/gzip.v
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vlib/compress/szip/szip.c.v
Expand Up @@ -7,6 +7,7 @@ import os

@[params]
pub struct ZipFolderOptions {
pub:
omit_empty_folders bool
}

Expand Down
2 changes: 2 additions & 0 deletions vlib/compress/zstd/zstd.v
Expand Up @@ -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
Expand Down Expand Up @@ -422,6 +423,7 @@ pub fn compress(data []u8, params CompressParams) ![]u8 {

@[params]
pub struct DecompressParams {
pub:
window_log_max int
}

Expand Down
1 change: 1 addition & 0 deletions vlib/dl/loader/loader.v
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions vlib/dlmalloc/dlmalloc.v
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions vlib/encoding/csv/README_csv_reader.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions vlib/encoding/csv/csv_reader_random_access.v
Expand Up @@ -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
Expand Down Expand Up @@ -344,6 +345,7 @@ pub fn (mut cr RandomAccessReader) get_row(y int) ![]string {

@[params]
pub struct GetCellConfig {
pub:
x int
y int
}
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions vlib/encoding/csv/csv_reader_sequential.v
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vlib/encoding/csv/reader.v
Expand Up @@ -52,6 +52,7 @@ mut:

@[params]
pub struct ReaderConfig {
pub:
delimiter u8 = `,`
comment u8 = `#`
}
Expand Down
1 change: 1 addition & 0 deletions vlib/encoding/csv/writer.v
Expand Up @@ -14,6 +14,7 @@ mut:

@[params]
pub struct WriterConfig {
pub:
use_crlf bool
delimiter u8 = `,`
}
Expand Down
2 changes: 2 additions & 0 deletions vlib/encoding/html/escape.v
Expand Up @@ -5,12 +5,14 @@ import strconv

@[params]
pub struct EscapeConfig {
pub:
quote bool = true
}

@[params]
pub struct UnescapeConfig {
EscapeConfig
pub:
all bool
}

Expand Down
2 changes: 2 additions & 0 deletions vlib/encoding/xml/entity.v
Expand Up @@ -20,6 +20,7 @@ pub const default_entities_reverse = {

@[params]
pub struct EscapeConfig {
pub:
reverse_entities map[string]string = xml.default_entities_reverse
}

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

Expand Down
4 changes: 4 additions & 0 deletions vlib/encoding/xml/types.v
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions vlib/gg/draw.c.v
Expand Up @@ -226,6 +226,7 @@ pub enum PaintStyle {

@[params]
pub struct DrawRectParams {
pub:
x f32
y f32
w f32
Expand Down
1 change: 1 addition & 0 deletions vlib/gg/gg.c.v
Expand Up @@ -545,6 +545,7 @@ pub enum EndEnum {

@[params]
pub struct EndOptions {
pub:
how EndEnum
}

Expand Down
1 change: 1 addition & 0 deletions vlib/gg/image.c.v
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vlib/gg/text_rendering.c.v
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vlib/io/buffered_reader.v
Expand Up @@ -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
Expand Down

0 comments on commit 1a35a78

Please sign in to comment.