Repository: hylo-lang/hylo (swift)

Issue:
Invalid mutable access when initializing buffers
For the following code:
```
public fun main() {
    var buf: MemoryAddress[2]
    &buf = [.null(), .null()]
}
```

We get "illegal mutable access" for each occurrence of `.null()`.

The Raw-IR is:
```
// bug.main
// Examples/bug.hylo:1.1-4:2
external fun FunctionDecl(1114114)() -> {} {
b0(%b0#0 : &{}):
  %i0.0: &PointerToMutable<Never>[2] = alloc_stack PointerToMutable<Never>[2]
  %i0.1: &PointerToMutable<Never>[2] = alloc_stack PointerToMutable<Never>[2]
  %i0.2: &PointerToMutable<Never> = %i0.1 advanced by 0 strides
  %i0.3: &PointerToMutable<Never> = access [set] %i0.2
  call @FunctionDecl(699334656)<Never>() to %i0.3
  end_access %i0.3
  %i0.6: &PointerToMutable<Never> = %i0.1 advanced by 1 strides
  %i0.7: &PointerToMutable<Never> = access [set] %i0.6
  call @FunctionDecl(699334656)<Never>() to %i0.7
  end_access %i0.7
  %i0.10: &PointerToMutable<Never>[2] = access [sink] %i0.1
  %i0.11: &PointerToMutable<Never>[2] = access [set] %i0.0
  memory_copy %i0.10, %i0.11
  end_access %i0.11
  mark_state deinitialized %i0.10
  end_access %i0.10
  dealloc_stack %i0.1
  dealloc_stack %i0.0
  mark_state initialized %b0#0
  return
}

// Hylo.PointerToMutable.null
// /Users/lucteo/work/hylo/hylo/StandardLibrary/Sources/Core/PointerToMutable.hylo:49.3-51:4
external fun FunctionDecl(699334656)() -> PointerToMutable<Pointee>
```

Pull request description:
Fix #1680

Patch:
diff --git a/Sources/IR/Module.swift b/Sources/IR/Module.swift
index 0b9c58401..d1247c841 100644
--- a/Sources/IR/Module.swift
+++ b/Sources/IR/Module.swift
@@ -122,6 +122,8 @@ public struct Module {
       return false
     case let s as AdvancedByBytes:
       return isBoundImmutably(s.base)
+    case let s as AdvancedByStrides:
+      return isBoundImmutably(s.base)
     case let s as Access:
       return isBoundImmutably(s.source)
     case let s as OpenCapture:


Test patch:
diff --git a/Tests/EndToEndTests/TestCases/BufferAssignment.hylo b/Tests/EndToEndTests/TestCases/BufferAssignment.hylo
new file mode 100644
index 000000000..1bef31159
--- /dev/null
+++ b/Tests/EndToEndTests/TestCases/BufferAssignment.hylo
@@ -0,0 +1,11 @@
+//- compileAndRun expecting: .success
+
+fun f() -> Int { 1 }
+
+public fun main() {
+  var x: Int[2]
+  &x = [f(), f()]
+  let p = pointer[to: x]
+  let q = Pointer<Int>(type_punning: p)
+  precondition(q.unsafe[] == 1)
+}