瀏覽代碼

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