Pārlūkot izejas kodu

codecgen: gen.go: fix bug gathering omitempty line (passes vet)

Ugorji Nwoke 8 gadi atpakaļ
vecāks
revīzija
00a57e09e3
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. 5 1
      codec/gen.go

+ 5 - 1
codec/gen.go

@@ -867,6 +867,8 @@ func (x *genRunner) encStruct(varname string, rtid uintptr, t reflect.Type) {
 			{
 				t2typ := t
 				varname3 := varname
+				// go through the loop, record the t2 field explicitly,
+				// and gather the omit line if embedded in pointers.
 				for ij, ix := range si.is {
 					if uint8(ij) == si.nis {
 						break
@@ -877,7 +879,9 @@ func (x *genRunner) encStruct(varname string, rtid uintptr, t reflect.Type) {
 					t2 = t2typ.Field(int(ix))
 					t2typ = t2.Type
 					varname3 = varname3 + "." + t2.Name
-					if t2typ.Kind() == reflect.Ptr {
+					// do not include actual field in the omit line.
+					// that is done subsequently (right after - below).
+					if uint8(ij+1) < si.nis && t2typ.Kind() == reflect.Ptr {
 						omitline += varname3 + " != nil && "
 					}
 				}