pull/13736/head
Nick Treleaven 2022-03-14 14:50:53 +00:00
parent e711fe6782
commit 7da28deaaf
1 changed files with 3 additions and 4 deletions

View File

@ -3763,8 +3763,8 @@ pub 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 (typ.is_ptr() && !typ.has_flag(.shared_f)
&& !node.left.is_auto_deref_var()) || typ.is_pointer() {
if (typ.is_ptr() && !typ.has_flag(.shared_f) && !node.left.is_auto_deref_var())
|| typ.is_pointer() {
mut is_ok := false
if mut node.left is ast.Ident {
if mut node.left.obj is ast.Var {
@ -3775,8 +3775,7 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
if !is_ok && node.index is ast.RangeExpr {
s := c.table.type_to_str(typ)
c.error('type `$s` does not support slicing', node.pos)
}
else if !c.inside_unsafe && !is_ok && !c.pref.translated && !c.file.is_translated {
} 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)
}
}