Skip to content

Commit

Permalink
all: more unsafe warnings => errors
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 8, 2024
1 parent 0224581 commit e1480b6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
8 changes: 4 additions & 4 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const type_level_cutoff_limit = 40 // it is very rarely deeper than 4
const iface_level_cutoff_limit = 100
const generic_fn_cutoff_limit_per_fn = 10_000 // how many times post_process_generic_fns, can visit the same function before bailing out

const generic_fn_postprocess_iterations_cutoff_limit = 1000_000
const generic_fn_postprocess_iterations_cutoff_limit = 1_000_000

// array_builtin_methods contains a list of all methods on array, that return other typed arrays,
// i.e. that act as *pseudogeneric* methods, that need compiler support, so that the types of the results
Expand Down Expand Up @@ -4707,12 +4707,12 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
&& typ_sym.kind == .map && node.or_expr.stmts.len == 0 {
elem_type := c.table.value_type(typ)
if elem_type.is_any_kind_of_pointer() {
c.note('accessing a pointer map value requires an `or {}` block outside `unsafe`',
c.warn('accessing a pointer map value requires an `or {}` block outside `unsafe`',
node.pos)
}
mut checked_types := []ast.Type{}
if c.is_contains_any_kind_of_pointer(elem_type, mut checked_types) {
c.note('accessing map value that contain pointers requires an `or {}` block outside `unsafe`',
c.warn('accessing map value that contain pointers requires an `or {}` block outside `unsafe`',
node.pos)
}
}
Expand All @@ -4738,7 +4738,7 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
} else if is_mut_struct {
c.error('type `mut ${typ_sym.name}` does not support slicing', node.pos)
} else if !c.inside_unsafe && !is_ok && !c.pref.translated && !c.file.is_translated {
c.warn('pointer indexing is only allowed in `unsafe` blocks', node.pos)
c.error('pointer indexing is only allowed in `unsafe` blocks', node.pos)
}
}
if mut node.index is ast.RangeExpr { // [1..2]
Expand Down
7 changes: 4 additions & 3 deletions vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
}
// record the vweb route methods (public non-generic methods):
if node.generic_names.len > 0 && node.is_pub {
typ_vweb_result := c.table.find_type_idx('vweb.Result')
typ_vweb_result := c.table.find_type_idx('veb.Result')
if node.return_type == typ_vweb_result {
rec_sym := c.table.sym(node.receiver.typ)
if rec_sym.kind == .struct_ {
if _ := c.table.find_field_with_embeds(rec_sym, 'Context') {
// there is no point in the message here, for methods that are not public; since they will not be available as routes anyway
c.note('generic method routes of vweb will be skipped', node.pos)
// there is no point in the message here, for methods
// that are not public; since they will not be available as routes anyway
c.note('generic method routes of veb will be skipped', node.pos)
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions vlib/v/checker/tests/index_sumtype_interface_struct_params_err.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
vlib/v/checker/tests/index_sumtype_interface_struct_params_err.vv:12:9: warning: pointer indexing is only allowed in `unsafe` blocks
10 |
11 | _ = st1[0]
12 | _ = st2[0]
| ~~~
13 | _ = st3[0]
14 | }
vlib/v/checker/tests/index_sumtype_interface_struct_params_err.vv:8:9: error: type `Foo` does not support indexing
6 |
6 |
7 | fn sum_type_or_interface_as_parameters(mut foo Foo, mut bar Bar, mut st1 Struct, st2 &Struct, st3 Struct) {
8 | _ = foo[0]
| ~~~
Expand All @@ -17,15 +10,22 @@ vlib/v/checker/tests/index_sumtype_interface_struct_params_err.vv:9:9: error: ty
8 | _ = foo[0]
9 | _ = bar[0]
| ~~~
10 |
10 |
11 | _ = st1[0]
vlib/v/checker/tests/index_sumtype_interface_struct_params_err.vv:11:9: error: type `mut Struct` does not support slicing
9 | _ = bar[0]
10 |
10 |
11 | _ = st1[0]
| ~~~
12 | _ = st2[0]
13 | _ = st3[0]
vlib/v/checker/tests/index_sumtype_interface_struct_params_err.vv:12:9: error: pointer indexing is only allowed in `unsafe` blocks
10 |
11 | _ = st1[0]
12 | _ = st2[0]
| ~~~
13 | _ = st3[0]
14 | }
vlib/v/checker/tests/index_sumtype_interface_struct_params_err.vv:13:9: error: type `Struct` does not support indexing
11 | _ = st1[0]
12 | _ = st2[0]
Expand Down
14 changes: 7 additions & 7 deletions vlib/v/checker/tests/map_index_reference_value.out
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
vlib/v/checker/tests/map_index_reference_value.vv:11:3: notice: accessing a pointer map value requires an `or {}` block outside `unsafe`
vlib/v/checker/tests/map_index_reference_value.vv:11:3: warning: accessing a pointer map value requires an `or {}` block outside `unsafe`
9 | fn main() {
10 | mut m := map[string]&Foo{}
11 | m['bar'].bar = 'bar'
| ~~~~~~~
12 | // m['bar'] << 'baz' // etc
13 |
vlib/v/checker/tests/map_index_reference_value.vv:11:3: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
vlib/v/checker/tests/map_index_reference_value.vv:11:3: warning: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
9 | fn main() {
10 | mut m := map[string]&Foo{}
11 | m['bar'].bar = 'bar'
| ~~~~~~~
12 | // m['bar'] << 'baz' // etc
13 |
vlib/v/checker/tests/map_index_reference_value.vv:15:8: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
13 |
vlib/v/checker/tests/map_index_reference_value.vv:15:8: warning: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
13 |
14 | mut m2 := map[string]Bar{}
15 | _ = m2['key']
| ~~~~~~~
16 |
16 |
17 | mut m3 := map[string][]Bar{}
vlib/v/checker/tests/map_index_reference_value.vv:18:8: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
16 |
vlib/v/checker/tests/map_index_reference_value.vv:18:8: warning: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
16 |
17 | mut m3 := map[string][]Bar{}
18 | _ = m3['key']
| ~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/checker/tests/unsafe_required.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ vlib/v/checker/tests/unsafe_required.vv:8:4: warning: method `S1.f` must be call
| ~~~
9 | }
10 |
vlib/v/checker/tests/unsafe_required.vv:16:7: warning: pointer indexing is only allowed in `unsafe` blocks
vlib/v/checker/tests/unsafe_required.vv:16:7: error: pointer indexing is only allowed in `unsafe` blocks
14 | _ = b[0] // OK
15 | c := &b
16 | _ = c[0]
| ~~~
17 |
18 | v := 4
vlib/v/checker/tests/unsafe_required.vv:20:7: warning: pointer indexing is only allowed in `unsafe` blocks
vlib/v/checker/tests/unsafe_required.vv:20:7: error: pointer indexing is only allowed in `unsafe` blocks
18 | v := 4
19 | p := &v
20 | _ = p[0]
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ fn (mut p Parser) attributes() {
start_pos := p.tok.pos()
mut is_at := false
if p.tok.kind == .lsbr {
p.note('`[attr]` has been deprecated, use `@[attr]` instead')
p.warn('`[attr]` has been deprecated, use `@[attr]` instead')
// [attr]
p.check(.lsbr)
} else if p.tok.kind == .at {
Expand Down

0 comments on commit e1480b6

Please sign in to comment.