diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 79409c039a..fc9f27fcce 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 623c85c63d..e84846d2ca 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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)