Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: turn warnings for private fields into errors (AFTER 2024-05-31) #21296

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1631,13 +1631,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
10 changes: 3 additions & 7 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,9 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
} else {
parts.last()
}
if !c.inside_unsafe {
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
}
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
13 changes: 4 additions & 9 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,11 +181,7 @@ pub fn (mut am AssetManager) add(asset_type string, file string) bool {
}
asset := Asset{
file_path: file
last_modified: unsafe {
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