Nim
Nim copied to clipboard
view outlive the location it was borrowed from
trafficstars
Example
{.experimental: "views".}
type
Foo = object
value: openArray[string]
proc main(): auto =
let a = ["1", "2", "3"]
let foo = Foo(value: a.toOpenArray(0, 2))
return foo
echo main()
https://play.nim-lang.org/#ix=41Mo
Current Output
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
Expected Output
Compile-time error
$ nim -v
Nim Compiler Version 1.6.6 [Windows: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf
active boot switches: -d:release