From 8324a766e89fc2404bd3d707e9b3a27ffdf802da Mon Sep 17 00:00:00 2001 From: BigBlack Date: Thu, 24 Jun 2021 17:39:42 +0800 Subject: [PATCH] checker: allow for `unsafe {*(p+1) = 22}` (#10557) --- vlib/v/checker/checker.v | 3 +++ vlib/v/tests/pointers_test.v | 2 ++ 2 files changed, 5 insertions(+) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 435e4b23a5..f651eced8f 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1599,6 +1599,9 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) { ast.StructInit { return '', pos } + ast.InfixExpr { + return '', pos + } else { if !expr.is_lit() { c.error('unexpected expression `$expr.type_name()`', expr.position()) diff --git a/vlib/v/tests/pointers_test.v b/vlib/v/tests/pointers_test.v index 2d6e780f80..cb5dbfd50d 100644 --- a/vlib/v/tests/pointers_test.v +++ b/vlib/v/tests/pointers_test.v @@ -7,6 +7,8 @@ fn test_pointer_arithmetic() { assert 2 == *parr parr++ assert 3 == *parr + parr_add_one := *(parr + 1) + assert parr_add_one == 4 assert *(parr + 1) == 4 } }