From 9e652c4f4022422c64c7135dded3efead880f856 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 26 Jul 2020 10:59:07 +0300 Subject: [PATCH] ci: fix remaining failing tests. Do mut ptr check only outside unsafe{} blocks. --- vlib/v/checker/checker.v | 2 +- vlib/v/tests/ptr_arithmetic_test.v | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b594d03ff3..68cf2167ba 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1601,7 +1601,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { if v := scope.find_var(ident.name) { if left_first is ast.Ident { assigned_var := left_first - if !v.is_mut && assigned_var.is_mut { + if !v.is_mut && assigned_var.is_mut && !c.inside_unsafe { c.error('`$ident.name` is immutable, cannot have a mutable reference to it', node.pos) } diff --git a/vlib/v/tests/ptr_arithmetic_test.v b/vlib/v/tests/ptr_arithmetic_test.v index 0d6bc29c25..c06cd21659 100644 --- a/vlib/v/tests/ptr_arithmetic_test.v +++ b/vlib/v/tests/ptr_arithmetic_test.v @@ -1,18 +1,24 @@ fn test_ptr_arithmetic(){ - v := 4 - mut p := &v unsafe { + // Do NOT move this outside unsafe{}. + // It causes too much churn in CI when new checks are implemented. + // If you want to implement a specific failing test, do so inside + // vlib/v/checker/tests/ , NOT here. + v := 4 + mut p := &v p++ p += 2 p = p - 1 + assert p == &v + 2 + p = p + 1 + assert p == &v + 3 + r := p++ + assert r == &v + 3 + assert p == &v + 4 } - assert p == unsafe {&v + 2} - p = unsafe { p + 1 } - assert p == unsafe {&v + 3} - r := unsafe { p++ } - assert r == unsafe {&v + 3} - assert p == unsafe {&v + 4} - +} + +fn test_ptr_arithmetic_over_byteptr() { // byteptr, voidptr, charptr are handled differently mut q := byteptr(10) unsafe {