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:
parent
9d056168ae
commit
9e652c4f40
@ -1601,7 +1601,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) {
|
|||||||
if v := scope.find_var(ident.name) {
|
if v := scope.find_var(ident.name) {
|
||||||
if left_first is ast.Ident {
|
if left_first is ast.Ident {
|
||||||
assigned_var := left_first
|
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',
|
c.error('`$ident.name` is immutable, cannot have a mutable reference to it',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,24 @@
|
|||||||
fn test_ptr_arithmetic(){
|
fn test_ptr_arithmetic(){
|
||||||
v := 4
|
|
||||||
mut p := &v
|
|
||||||
unsafe {
|
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++
|
||||||
p += 2
|
p += 2
|
||||||
p = p - 1
|
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}
|
fn test_ptr_arithmetic_over_byteptr() {
|
||||||
r := unsafe { p++ }
|
|
||||||
assert r == unsafe {&v + 3}
|
|
||||||
assert p == unsafe {&v + 4}
|
|
||||||
|
|
||||||
// byteptr, voidptr, charptr are handled differently
|
// byteptr, voidptr, charptr are handled differently
|
||||||
mut q := byteptr(10)
|
mut q := byteptr(10)
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Loading…
Reference in New Issue
Block a user