1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: Warn instead of error for pointer arithmetic (#5840)

This commit is contained in:
Nick Treleaven 2020-07-15 18:59:39 +01:00 committed by GitHub
parent 1873a0cb6d
commit 4b0ded0475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -480,7 +480,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
right_pos := infix_expr.right.position()
if (left_type.is_ptr() || left.is_pointer()) &&
infix_expr.op in [.plus, .minus] && !c.inside_unsafe {
c.error('pointer arithmetic is only allowed in `unsafe` blocks', left_pos)
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', left_pos)
}
mut return_type := left_type
// Single side check
@ -1632,7 +1632,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
right_sym := c.table.get_type_symbol(right_type_unwrapped)
if (left_type.is_ptr() || left_sym.is_pointer()) &&
assign_stmt.op !in [.assign, .decl_assign] && !c.inside_unsafe {
c.error('pointer arithmetic is only allowed in `unsafe` blocks', assign_stmt.pos)
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', assign_stmt.pos)
}
// Single side check
match assign_stmt.op {
@ -2876,7 +2876,7 @@ pub fn (mut c Checker) postfix_expr(mut node ast.PostfixExpr) table.Type {
node.auto_locked, _ = c.fail_if_immutable(node.expr)
}
if (typ.is_ptr() || typ_sym.is_pointer()) && !c.inside_unsafe {
c.error('pointer arithmetic is only allowed in `unsafe` blocks', node.pos)
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', node.pos)
}
return typ
}