It's not possible to make a view of a [non thread local variable declared as 
var](https://nim-lang.github.io/Nim/manual_experimental.html#view-types). So 
the following code doesn't compile:
    
    
    {.experimental: "views".}
    
    var someArray = [0]
    
    proc main() =
      let viewOfArray: openArray[int] = someArray
    
    main()
    
    
    Run
    
    
    /usercode/in.nim(6, 37) Error: cannot borrow from someArray, it is not a 
path expression; see 
https://nim-lang.github.io/Nim/manual_experimental.html#view-types-algorithm-path-expressions
 for details
    
    
    Run

But there's a workaround:
    
    
    {.experimental: "views".}
    
    var someArray = [0]
    
    proc takeOpenArray(arr: openArray[int]) =
      let viewOfView: openArray[int] = arr
    
    proc main() =
      takeOpenArray someArray
    
    main()
    
    
    Run

  1. Why is this not allowed? The manual doesn't explain it. (also the link in 
the error message both doesn't work and why it doesn't work is described in a 
different section)
  2. Is my workaround just an oversight? And if yes how will it be prevented, 
will the creation of the view with the call already be an error?


Reply via email to