Skip to content

copied ref object is converted to nil if not used in the declaration module under ARC/ORC even it's exported #19312

@hamidb80

Description

@hamidb80

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:

echo b[]
echo a[]

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.

(val: 1)
(val: 1)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions