Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix empty slice is converted to nil in un ConvertibleTo case #164

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

hhh111119
Copy link

@hhh111119 hhh111119 commented Sep 16, 2022

fix an empty slice is converted to nil issue. could check the test case add by me.

func TestEmptySlice(t *testing.T) {
	type Str1 string
	type Str2 string
	type Input1 struct {
		Val Str1
	}
	type Input2 struct {
		Val Str2
	}
	to := []*Input1(nil)
	from := []*Input2{}
	err := copier.Copy(&to, &from)
	if err != nil {
		t.Error("should not error")
	}
	if from == nil {
		t.Error("from should be empty slice not nil")
	}

	to = []*Input1(nil)
	from = []*Input2(nil)
	err = copier.Copy(&to, &from)
	if err != nil {
		t.Error("should not error")
	}
	if from != nil {
		t.Error("from should be empty slice nil")
	}
}

@jinzhu jinzhu merged commit 0e264e9 into jinzhu:master Sep 16, 2022
@hhh111119 hhh111119 deleted the fix_empty_slice_to_nil branch September 16, 2022 10:35
@archiewx
Copy link

archiewx commented Jan 9, 2023

Why not release a new version of pkg

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.

3 participants