mirror of
https://github.com/vlang/v.git
synced 2025-08-04 10:17:22 -04:00
checker: turn warnings for private fields into errors (#21296)
This commit is contained in:
parent
da4afef0d7
commit
dfc0c91295
@ -32,7 +32,6 @@ const time_to_test = time.Time{
|
|||||||
minute: 23
|
minute: 23
|
||||||
second: 42
|
second: 42
|
||||||
nanosecond: 123456789
|
nanosecond: 123456789
|
||||||
unix: 332198622
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println(time_to_test.format())
|
println(time_to_test.format())
|
||||||
|
@ -219,7 +219,6 @@ fn test_weekday_str() {
|
|||||||
hour: 0
|
hour: 0
|
||||||
minute: 0
|
minute: 0
|
||||||
second: 0
|
second: 0
|
||||||
// unix: 0
|
|
||||||
}
|
}
|
||||||
assert t.weekday_str() == name
|
assert t.weekday_str() == name
|
||||||
}
|
}
|
||||||
|
@ -1631,13 +1631,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
|
|||||||
is_used_outside := sym.mod != c.mod
|
is_used_outside := sym.mod != c.mod
|
||||||
if is_used_outside && !field.is_pub && sym.language != .c {
|
if is_used_outside && !field.is_pub && sym.language != .c {
|
||||||
unwrapped_sym := c.table.sym(c.unwrap_generic(typ))
|
unwrapped_sym := c.table.sym(c.unwrap_generic(typ))
|
||||||
if unwrapped_sym.kind == .struct_ && unwrapped_sym.name == 'time.Time' {
|
c.error('field `${unwrapped_sym.name}.${field_name}` is not public', node.pos)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
field_sym := c.table.sym(field.typ)
|
field_sym := c.table.sym(field.typ)
|
||||||
if field.is_deprecated && is_used_outside {
|
if field.is_deprecated && is_used_outside {
|
||||||
|
@ -758,13 +758,9 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
|||||||
} else {
|
} else {
|
||||||
parts.last()
|
parts.last()
|
||||||
}
|
}
|
||||||
if !c.inside_unsafe {
|
c.error('cannot access private field `${field.name}` on `${mod_type}`',
|
||||||
c.add_error_detail('this will become an error after 2024-05-31')
|
init_field.pos)
|
||||||
c.warn('initalizing private field `${field.name}` of `${mod_type}`',
|
break
|
||||||
init_field.pos)
|
|
||||||
// c.error('cannot access private field `${field.name}` on `${mod_type}`', init_field.pos)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 |
|
6 |
|
||||||
7 | _ := amod.Bcg{
|
7 | _ := amod.Bcg{
|
||||||
8 | x: 0
|
8 | x: 0
|
||||||
| ~~~~
|
| ~~~~
|
||||||
9 | }
|
9 | }
|
||||||
10 |
|
10 |
|
||||||
Details: this will become an error after 2024-05-31
|
vlib/v/checker/tests/struct_field_private_err.vv:11:10: error: cannot access private field `bar` on `amod.FooParams`
|
||||||
vlib/v/checker/tests/struct_field_private_err.vv:11:10: warning: initalizing private field `bar` of `amod.FooParams`
|
|
||||||
9 | }
|
9 | }
|
||||||
10 |
|
10 |
|
||||||
11 | amod.foo(bar: 'bar')
|
11 | amod.foo(bar: 'bar')
|
||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
Details: this will become an error after 2024-05-31
|
|
||||||
|
@ -3,7 +3,6 @@ module assets
|
|||||||
// this module provides an AssetManager for combining
|
// this module provides an AssetManager for combining
|
||||||
// and caching javascript & css.
|
// and caching javascript & css.
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import crypto.md5
|
import crypto.md5
|
||||||
|
|
||||||
const unknown_asset_type_error = 'vweb.assets: unknown asset type'
|
const unknown_asset_type_error = 'vweb.assets: unknown asset type'
|
||||||
@ -21,7 +20,7 @@ pub mut:
|
|||||||
|
|
||||||
struct Asset {
|
struct Asset {
|
||||||
file_path string
|
file_path string
|
||||||
last_modified time.Time
|
last_modified i64
|
||||||
mut:
|
mut:
|
||||||
include_name string
|
include_name string
|
||||||
}
|
}
|
||||||
@ -131,8 +130,8 @@ fn (am AssetManager) get_cache_key(asset_type string) string {
|
|||||||
mut latest_modified := i64(0)
|
mut latest_modified := i64(0)
|
||||||
for asset in am.get_assets(asset_type) {
|
for asset in am.get_assets(asset_type) {
|
||||||
files_salt += asset.file_path
|
files_salt += asset.file_path
|
||||||
if asset.last_modified.unix() > latest_modified {
|
if asset.last_modified > latest_modified {
|
||||||
latest_modified = asset.last_modified.unix()
|
latest_modified = asset.last_modified
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hash := md5.sum(files_salt.bytes()).hex()
|
hash := md5.sum(files_salt.bytes()).hex()
|
||||||
@ -182,11 +181,7 @@ pub fn (mut am AssetManager) add(asset_type string, file string) bool {
|
|||||||
}
|
}
|
||||||
asset := Asset{
|
asset := Asset{
|
||||||
file_path: file
|
file_path: file
|
||||||
last_modified: unsafe {
|
last_modified: os.file_last_mod_unix(file)
|
||||||
time.Time{
|
|
||||||
unix: os.file_last_mod_unix(file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if asset_type == 'css' {
|
if asset_type == 'css' {
|
||||||
am.css << asset
|
am.css << asset
|
||||||
|
@ -2,15 +2,14 @@ module json2
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
const fixed_time = time.Time{
|
const fixed_time = time.new(
|
||||||
year: 2022
|
year: 2022
|
||||||
month: 3
|
month: 3
|
||||||
day: 11
|
day: 11
|
||||||
hour: 13
|
hour: 13
|
||||||
minute: 54
|
minute: 54
|
||||||
second: 25
|
second: 25
|
||||||
// unix: 1647006865
|
)
|
||||||
}
|
|
||||||
|
|
||||||
type StringAlias = string
|
type StringAlias = string
|
||||||
type BoolAlias = bool
|
type BoolAlias = bool
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import x.json2.decoder2 as json
|
import x.json2.decoder2 as json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
const fixed_time = time.Time{
|
const fixed_time = time.new(
|
||||||
year: 2022
|
year: 2022
|
||||||
month: 3
|
month: 3
|
||||||
day: 11
|
day: 11
|
||||||
hour: 13
|
hour: 13
|
||||||
minute: 54
|
minute: 54
|
||||||
second: 25
|
second: 25
|
||||||
// unix: 1647006865
|
)
|
||||||
}
|
|
||||||
|
|
||||||
type StringAlias = string
|
type StringAlias = string
|
||||||
type BoolAlias = bool
|
type BoolAlias = bool
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import x.json2 as json
|
import x.json2 as json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
const fixed_time = time.Time{
|
const fixed_time = time.new(
|
||||||
year: 2022
|
year: 2022
|
||||||
month: 3
|
month: 3
|
||||||
day: 11
|
day: 11
|
||||||
hour: 13
|
hour: 13
|
||||||
minute: 54
|
minute: 54
|
||||||
second: 25
|
second: 25
|
||||||
// unix: 1647006865
|
)
|
||||||
}
|
|
||||||
|
|
||||||
type StringAlias = string
|
type StringAlias = string
|
||||||
type BoolAlias = bool
|
type BoolAlias = bool
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import x.json2 as json
|
import x.json2 as json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
const fixed_time = time.Time{
|
const fixed_time = time.new(
|
||||||
year: 2022
|
year: 2022
|
||||||
month: 3
|
month: 3
|
||||||
day: 11
|
day: 11
|
||||||
hour: 13
|
hour: 13
|
||||||
minute: 54
|
minute: 54
|
||||||
second: 25
|
second: 25
|
||||||
// unix: 1647006865
|
)
|
||||||
}
|
|
||||||
|
|
||||||
type StringAlias = string
|
type StringAlias = string
|
||||||
type BoolAlias = bool
|
type BoolAlias = bool
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import x.json2 as json
|
import x.json2 as json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
const fixed_time = time.Time{
|
const fixed_time = time.new(
|
||||||
year: 2022
|
year: 2022
|
||||||
month: 3
|
month: 3
|
||||||
day: 11
|
day: 11
|
||||||
hour: 13
|
hour: 13
|
||||||
minute: 54
|
minute: 54
|
||||||
second: 25
|
second: 25
|
||||||
// unix: 1647006865
|
)
|
||||||
}
|
|
||||||
|
|
||||||
type StringAlias = string
|
type StringAlias = string
|
||||||
type BoolAlias = bool
|
type BoolAlias = bool
|
||||||
|
Loading…
x
Reference in New Issue
Block a user