copier icon indicating copy to clipboard operation
copier copied to clipboard

Unexported fields behaviour

Open matthieujoossen opened this issue 2 years ago • 3 comments

Does the copier tag applied to unexported fields

I saw that an issue have been resolved for unexported fields (#111).

But I'm surprised that unexported fields are copied in the case copier tag is set to -.

See an exemple here: https://go.dev/play/p/oW9t1vJVPX-

matthieujoossen avatar Apr 15 '22 08:04 matthieujoossen

private tag will be ignore

func deepFields(reflectType reflect.Type) []reflect.StructField {
	if reflectType, _ = indirectType(reflectType); reflectType.Kind() == reflect.Struct {
		fields := make([]reflect.StructField, 0, reflectType.NumField())

		for i := 0; i < reflectType.NumField(); i++ {
			v := reflectType.Field(i)
			// PkgPath is the package path that qualifies a lower case (unexported)
			// field name. It is empty for upper case (exported) field names.
			// See https://golang.org/ref/spec#Uniqueness_of_identifiers
			//if v.PkgPath == "" {
			fields = append(fields, v)
			if v.Anonymous {
				// also consider fields of anonymous fields as fields of the root
				fields = append(fields, deepFields(v.Type)...)
			}
			//}
		}

		return fields
	}

	return nil
}

lixiandea avatar Apr 26 '22 14:04 lixiandea

Hi,

@lixiandea , I'm not sure to understand the reason of your message. I'm showing that private tags are not ignored. My question is about the expected behaviour.

matthieujoossen avatar May 16 '22 09:05 matthieujoossen

@jinzhu I still have the issue with v0.4.0. Why did you choose to copy the private fields?

matthieuzbo avatar Sep 14 '23 13:09 matthieuzbo