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

ci: fix remaining failing tests. Do mut ptr check only outside unsafe{} blocks.

This commit is contained in:
Delyan Angelov 2020-07-26 10:59:07 +03:00
parent 9d056168ae
commit 9e652c4f40
2 changed files with 16 additions and 10 deletions

View File

@ -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)
}

View File

@ -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 {