فهرست منبع

codecgen: account for zero external packages when generating version check in init.

Previously, we (very wrongly) didn't account for the situation
where the type did not reference any packages outside the current one.

We now fix it by checking first if number of external packages referenced
is greater than zero.

Fixes #45
Ugorji Nwoke 11 سال پیش
والد
کامیت
c11bd15611
1فایلهای تغییر یافته به همراه7 افزوده شده و 10 حذف شده
  1. 7 10
      codec/gen.go

+ 7 - 10
codec/gen.go

@@ -203,18 +203,15 @@ func Gen(w io.Writer, buildTags, pkgName string, useUnsafe bool, typ ...reflect.
 		x.linef("var v%v unsafe.Pointer", n)
 		n++
 	}
-	for i := 0; i < n; i++ {
-		if i != 0 {
-			x.out(", ")
-		}
+	if n > 0 {
 		x.out("_")
-	}
-	x.out(" = ")
-	for i := 0; i < n; i++ {
-		if i != 0 {
-			x.out(", ")
+		for i := 1; i < n; i++ {
+			x.out(", _")
+		}
+		x.out(" = v0")
+		for i := 1; i < n; i++ {
+			x.outf(", v%v", i)
 		}
-		x.outf("v%v", i)
 	}
 	x.line("} ") // close if false
 	x.line("}")  // close init