Skip to content

=copy hook for seq appears to be broken #22664

@PMunch

Description

@PMunch

Description

When wrapping MAPR I wanted to test my hooks with Valgrind to make sure I had gotten them right. What I ended up with was finding a bug in the =copy hook for sequences placed in ref objects. The smallest reproduction I've been able to create is this:

type ElementKind* = enum String, Number Element* = object case kind*: ElementKind  of String: str*: string  of Number: num*: float Calc = ref object stack: seq[Element] var calc = new Calc calc.stack.add Element(kind: Number, num: 200.0) echo "Calc stack before: ", calc.stack echo "---" let calc2 = calc calc2.stack = calc.stack # This nulls out the object in the stack echo "Calc stack after: ", calc.stack echo "Calc2 stack after: ", calc2.stack

If a simple seq[int] is used the program behaves as expected. So it appears to only happen for more complex objects. The reason is that =copy is triggered on calc.stack to calc2.stack and the hook doesn't check if they are already equal.

Nim Version

Both 2.0.0 and the current devel

Current Output

Calc stack before: @[(kind: Number, num: 200.0)] --- Calc stack after: @[(kind: String, str: "")] Calc2 stack after: @[(kind: String, str: "")] 

Expected Output

Calc stack before: @[(kind: Number, num: 200.0)] --- Calc stack after: @[(kind: Number, num: 200.0)] Calc2 stack after: @[(kind: Number, num: 200.0)] 

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions