mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: require unsafe for accessing a pointer map value
This commit is contained in:
parent
b25c9e8bbf
commit
877a1e511a
@ -3812,6 +3812,15 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
|
||||
'(note, that variables may be mutable but string values are always immutable, like in Go and Java)',
|
||||
node.pos)
|
||||
}
|
||||
|
||||
if !c.inside_unsafe && !c.is_builtin_mod && typ_sym.kind == .map && node.or_expr.stmts.len == 0 {
|
||||
elem_type := c.table.value_type(typ)
|
||||
if elem_type.is_real_pointer() {
|
||||
c.note('accessing a pointer map value requires an `or{}` block outside `unsafe`',
|
||||
node.pos)
|
||||
}
|
||||
}
|
||||
|
||||
if (typ.is_ptr() && !typ.has_flag(.shared_f) && !node.left.is_auto_deref_var())
|
||||
|| typ.is_pointer() {
|
||||
mut is_ok := false
|
||||
|
@ -2007,7 +2007,9 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
save_inner_loop := g.inner_loop
|
||||
g.inner_loop = unsafe { &node }
|
||||
if node.label != '' {
|
||||
g.labeled_loops[node.label] = unsafe { &node }
|
||||
unsafe {
|
||||
g.labeled_loops[node.label] = &node
|
||||
}
|
||||
}
|
||||
g.write_v_source_line_info(node.pos)
|
||||
g.for_c_stmt(node)
|
||||
@ -2021,7 +2023,9 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
save_inner_loop := g.inner_loop
|
||||
g.inner_loop = unsafe { &node }
|
||||
if node.label != '' {
|
||||
g.labeled_loops[node.label] = unsafe { &node }
|
||||
unsafe {
|
||||
g.labeled_loops[node.label] = &node
|
||||
}
|
||||
}
|
||||
g.write_v_source_line_info(node.pos)
|
||||
g.for_in_stmt(node)
|
||||
@ -2035,7 +2039,9 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
save_inner_loop := g.inner_loop
|
||||
g.inner_loop = unsafe { &node }
|
||||
if node.label != '' {
|
||||
g.labeled_loops[node.label] = unsafe { &node }
|
||||
unsafe {
|
||||
g.labeled_loops[node.label] = &node
|
||||
}
|
||||
}
|
||||
g.write_v_source_line_info(node.pos)
|
||||
g.for_stmt(node)
|
||||
|
Loading…
Reference in New Issue
Block a user