This code snippet compiles and run without problem
{.experimental: "views".}
block:
type
Obj = ref object
f: cstring
proc borrow(o: Obj): openArray[char] = toOpenArray(o.f, 0, 0)
let o = Obj()
let r = o.borrow()
This one can't get compiled
block:
type
Obj = ref object
f: UncheckedArray[char]
proc borrow(o: Obj): openArray[char] =
toOpenArray(addr o.f, 0, 0)
let o = new Obj
let r = o.borrow()
nim reports
Error: cannot borrow from toOpenArray(addr o.f, 0, 0), it is not a path expression; see https://nim-lang.github.io/Nim/manual_experimental.html#view-types-algorithm-path-expressions for details
Although o.f is derived from o, the first parameter of borrow(), but I have to addr it to get ptr UncheckedArray[T] to pass to toOpenArray().
Are there any other way around to solve it?