Skip to content

Commit

Permalink
checker: turn warnings for private fields into errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 17, 2024
1 parent 1363cc8 commit 7b98dc6
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 38 deletions.
1 change: 0 additions & 1 deletion vlib/time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const time_to_test = time.Time{
minute: 23
second: 42
nanosecond: 123456789
unix: 332198622
}
println(time_to_test.format())
Expand Down
1 change: 0 additions & 1 deletion vlib/time/time_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ fn test_weekday_str() {
hour: 0
minute: 0
second: 0
unix: 0
}
assert t.weekday_str() == name
}
Expand Down
8 changes: 1 addition & 7 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -1625,13 +1625,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
is_used_outside := sym.mod != c.mod
if is_used_outside && !field.is_pub && sym.language != .c {
unwrapped_sym := c.table.sym(c.unwrap_generic(typ))
if unwrapped_sym.kind == .struct_ && unwrapped_sym.name == 'time.Time' {
c.add_error_detail('this will become an error after 2024-05-31')
c.warn('field `${unwrapped_sym.name}.${field_name}` is not public, use `${node.expr}.unix()` instead',
node.pos)
} else {
c.error('field `${unwrapped_sym.name}.${field_name}` is not public', node.pos)
}
c.error('field `${unwrapped_sym.name}.${field_name}` is not public', node.pos)
}
field_sym := c.table.sym(field.typ)
if field.is_deprecated && is_used_outside {
Expand Down
4 changes: 1 addition & 3 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,8 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
} 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}`',
c.error('cannot access private field `${field.name}` on `${mod_type}`',
init_field.pos)
// c.error('cannot access private field `${field.name}` on `${mod_type}`', init_field.pos)
break
}
}
Expand Down
6 changes: 2 additions & 4 deletions vlib/v/checker/tests/struct_field_private_err.out
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
vlib/v/checker/tests/struct_field_private_err.vv:8:2: warning: initalizing private field `x` of `amod.Bcg`
vlib/v/checker/tests/struct_field_private_err.vv:8:2: error: cannot access private field `x` on `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`
vlib/v/checker/tests/struct_field_private_err.vv:11:10: error: cannot access private field `bar` on `amod.FooParams`
9 | }
10 |
11 | amod.foo(bar: 'bar')
| ~~~~~~~~~~
Details: this will become an error after 2024-05-31
11 changes: 11 additions & 0 deletions vlib/v/util/diff/diff.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ module diff
import os
import time

enum DiffTools {
colordiff
diff
opendiff
}

// find_working_diff_command returns the first available command from a list of known diff cli tools.
pub fn find_working_diff_command() !string {
env_difftool := os.getenv('VDIFF_TOOL')
Expand Down Expand Up @@ -33,6 +39,11 @@ pub fn find_working_diff_command() !string {
}

// color_compare_files returns a colored diff between two files.
// NOTE:
// - `code` won't return a string / not diff tool tool for the job
// - Only via env opts
// - `gdiff` ?
// TODO: checkout opendiff
pub fn color_compare_files(diff_cmd string, path1 string, path2 string) string {
cmd := diff_cmd.all_before(' ')
os.find_abs_path_of_executable(cmd) or { return 'comparison command: `${cmd}` not found' }
Expand Down
11 changes: 4 additions & 7 deletions vlib/vweb/assets/assets.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module assets
// this module provides an AssetManager for combining
// and caching javascript & css.
import os
import time
import crypto.md5

const unknown_asset_type_error = 'vweb.assets: unknown asset type'
Expand All @@ -21,7 +20,7 @@ pub mut:

struct Asset {
file_path string
last_modified time.Time
last_modified i64
mut:
include_name string
}
Expand Down Expand Up @@ -131,8 +130,8 @@ fn (am AssetManager) get_cache_key(asset_type string) string {
mut latest_modified := i64(0)
for asset in am.get_assets(asset_type) {
files_salt += asset.file_path
if asset.last_modified.unix() > latest_modified {
latest_modified = asset.last_modified.unix()
if asset.last_modified > latest_modified {
latest_modified = asset.last_modified
}
}
hash := md5.sum(files_salt.bytes()).hex()
Expand Down Expand Up @@ -182,9 +181,7 @@ pub fn (mut am AssetManager) add(asset_type string, file string) bool {
}
asset := Asset{
file_path: file
last_modified: time.Time{
unix: os.file_last_mod_unix(file)
}
last_modified: os.file_last_mod_unix(file)
}
if asset_type == 'css' {
am.css << asset
Expand Down
5 changes: 2 additions & 3 deletions vlib/x/json2/count_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ module json2

import time

const fixed_time = time.Time{
const fixed_time = time.new(
year: 2022
month: 3
day: 11
hour: 13
minute: 54
second: 25
unix: 1647006865
}
)

type StringAlias = string
type BoolAlias = bool
Expand Down
5 changes: 2 additions & 3 deletions vlib/x/json2/decoder2/tests/decode_struct_test.v
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import x.json2.decoder2 as json
import time

const fixed_time = time.Time{
const fixed_time = time.new(
year: 2022
month: 3
day: 11
hour: 13
minute: 54
second: 25
unix: 1647006865
}
)

type StringAlias = string
type BoolAlias = bool
Expand Down
5 changes: 2 additions & 3 deletions vlib/x/json2/tests/decode_struct_test.v
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import x.json2 as json
import time

const fixed_time = time.Time{
const fixed_time = time.new(
year: 2022
month: 3
day: 11
hour: 13
minute: 54
second: 25
unix: 1647006865
}
)

type StringAlias = string
type BoolAlias = bool
Expand Down
5 changes: 2 additions & 3 deletions vlib/x/json2/tests/encode_struct_test.v
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import x.json2 as json
import time

const fixed_time = time.Time{
const fixed_time = time.new(
year: 2022
month: 3
day: 11
hour: 13
minute: 54
second: 25
unix: 1647006865
}
)

type StringAlias = string
type BoolAlias = bool
Expand Down
5 changes: 2 additions & 3 deletions vlib/x/json2/tests/encode_struct_todo_test.vv
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import x.json2 as json
import time

const fixed_time = time.Time{
const fixed_time = time.new(
year: 2022
month: 3
day: 11
hour: 13
minute: 54
second: 25
unix: 1647006865
}
)

type StringAlias = string
type BoolAlias = bool
Expand Down

0 comments on commit 7b98dc6

Please sign in to comment.