Skip to content

To support copy []any to []T#235

Open
happier233 wants to merge 1 commit intojinzhu:masterfrom
happier233:master
Open

To support copy []any to []T#235
happier233 wants to merge 1 commit intojinzhu:masterfrom
happier233:master

Conversation

@happier233
Copy link
Copy Markdown

@happier233 happier233 commented Oct 2, 2025

refs #234

@happier233
Copy link
Copy Markdown
Author

@jinzhu Please help to review this PR.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for copying []any (i.e., []interface{}) to typed slices []T when the DeepCopy option is enabled, addressing issue #234 where copying []interface{} containing map[string]interface{} values to []map[string]string failed silently.

Changes:

  • Modified the slice copy condition in copier.go to also enter the element-by-element copy loop when DeepCopy is enabled, not only when types are directly convertible.
  • Added tests for both DeepCopy: true (successful copy) and DeepCopy: false (preserves existing no-op behavior) scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
copier.go Adds opt.DeepCopy as an alternative condition to enter the slice element copy loop
copier_different_type_test.go Adds TestCopyWithAnySlice with subtests for deep copy and non-deep copy of []interface{}[]map[string]string

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if err != nil {
t.Errorf("CopyStructWithOption() error = %v", err)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants