Hey,
I guess the title was a little confusing for you, so let's dive into the examples
Example
let's say we have a ref object called RefWrapper that wraps and integer in the main.nim file.
type
Wrapper* = object
val: int
RefWrapper* = ref Wrapper
let
a* = RefWrapper(val: 1)
b* = a
I put this lines at the the end of main.nim:
the output of the program will be 2 (val: 1) which is correct.
but let's cut those last 2 lines and paste them in a another file called play.nim
import main
echo b[]
echo a[]
Current Output
if you run the program, it echoes a (val: 1) then crashes due to this error:
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Expected Output
works like the first program.
Possible Solution
- maybe consider exported
ref types ?
Additional Information
OS: windows 10 64bit
>> nim -v
Nim Compiler Version 1.6.2 [Windows: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf
active boot switches: -d:release