goprotobuf: Explicitly type the generated enum constants.

R=r
CC=golang-dev
http://codereview.appspot.com/4952045
diff --git a/compiler/generator/generator.go b/compiler/generator/generator.go
index 760c5bf..34d3ad2 100644
--- a/compiler/generator/generator.go
+++ b/compiler/generator/generator.go
@@ -289,7 +289,7 @@
 	g.P("type ", s, " ", pkg, ".", s)
 	g.P("var ", s, "_name = ", pkg, ".", s, "_name")
 	g.P("var ", s, "_value = ", pkg, ".", s, "_value")
-	g.P("func New", s, "(x int32) *", s, " { e := ", s, "(x); return &e }")
+	g.P("func New", s, "(x ", s, ") *", s, " { e := ", s, "(x); return &e }")
 }
 
 type constOrVarSymbol struct {
@@ -893,7 +893,7 @@
 	g.In()
 	for _, e := range enum.Value {
 		name := ccPrefix + *e.Name
-		g.P(name, " = ", e.Number)
+		g.P(name, " ", ccTypeName, " = ", e.Number)
 		g.file.addExport(enum, constOrVarSymbol{name, "const"})
 	}
 	g.Out()
@@ -919,7 +919,7 @@
 	g.Out()
 	g.P("}")
 
-	g.P("func New", ccTypeName, "(x int32) *", ccTypeName, " {")
+	g.P("func New", ccTypeName, "(x ", ccTypeName, ") *", ccTypeName, " {")
 	g.In()
 	g.P("e := ", ccTypeName, "(x)")
 	g.P("return &e")
diff --git a/compiler/testdata/imp.pb.go.golden b/compiler/testdata/imp.pb.go.golden
index 8c7edfd..6ee0d1a 100644
--- a/compiler/testdata/imp.pb.go.golden
+++ b/compiler/testdata/imp.pb.go.golden
@@ -26,8 +26,8 @@
 type ImportedMessage_Owner int32
 
 const (
-	ImportedMessage_DAVE = 1
-	ImportedMessage_MIKE = 2
+	ImportedMessage_DAVE ImportedMessage_Owner = 1
+	ImportedMessage_MIKE ImportedMessage_Owner = 2
 )
 
 var ImportedMessage_Owner_name = map[int32]string{
@@ -39,7 +39,7 @@
 	"MIKE": 2,
 }
 
-func NewImportedMessage_Owner(x int32) *ImportedMessage_Owner {
+func NewImportedMessage_Owner(x ImportedMessage_Owner) *ImportedMessage_Owner {
 	e := ImportedMessage_Owner(x)
 	return &e
 }
diff --git a/compiler/testdata/test.pb.go.golden b/compiler/testdata/test.pb.go.golden
index 1295e07..4875d71 100644
--- a/compiler/testdata/test.pb.go.golden
+++ b/compiler/testdata/test.pb.go.golden
@@ -17,8 +17,8 @@
 type HatType int32
 
 const (
-	HatType_FEDORA = 1
-	HatType_FEZ    = 2
+	HatType_FEDORA HatType = 1
+	HatType_FEZ    HatType = 2
 )
 
 var HatType_name = map[int32]string{
@@ -30,7 +30,7 @@
 	"FEZ":    2,
 }
 
-func NewHatType(x int32) *HatType {
+func NewHatType(x HatType) *HatType {
 	e := HatType(x)
 	return &e
 }
@@ -41,9 +41,9 @@
 type Days int32
 
 const (
-	Days_MONDAY  = 1
-	Days_TUESDAY = 2
-	Days_LUNDI   = 1
+	Days_MONDAY  Days = 1
+	Days_TUESDAY Days = 2
+	Days_LUNDI   Days = 1
 )
 
 var Days_name = map[int32]string{
@@ -57,7 +57,7 @@
 	"LUNDI":   1,
 }
 
-func NewDays(x int32) *Days {
+func NewDays(x Days) *Days {
 	e := Days(x)
 	return &e
 }
@@ -68,9 +68,9 @@
 type Request_Color int32
 
 const (
-	Request_RED   = 0
-	Request_GREEN = 1
-	Request_BLUE  = 2
+	Request_RED   Request_Color = 0
+	Request_GREEN Request_Color = 1
+	Request_BLUE  Request_Color = 2
 )
 
 var Request_Color_name = map[int32]string{
@@ -84,7 +84,7 @@
 	"BLUE":  2,
 }
 
-func NewRequest_Color(x int32) *Request_Color {
+func NewRequest_Color(x Request_Color) *Request_Color {
 	e := Request_Color(x)
 	return &e
 }
@@ -95,8 +95,8 @@
 type Reply_Entry_Game int32
 
 const (
-	Reply_Entry_FOOTBALL = 1
-	Reply_Entry_TENNIS   = 2
+	Reply_Entry_FOOTBALL Reply_Entry_Game = 1
+	Reply_Entry_TENNIS   Reply_Entry_Game = 2
 )
 
 var Reply_Entry_Game_name = map[int32]string{
@@ -108,7 +108,7 @@
 	"TENNIS":   2,
 }
 
-func NewReply_Entry_Game(x int32) *Reply_Entry_Game {
+func NewReply_Entry_Game(x Reply_Entry_Game) *Reply_Entry_Game {
 	e := Reply_Entry_Game(x)
 	return &e
 }
diff --git a/proto/all_test.go b/proto/all_test.go
index dd7f66e..256ab4c 100644
--- a/proto/all_test.go
+++ b/proto/all_test.go
@@ -112,7 +112,7 @@
 		pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted)
 	}
 
-	pb.Kind = Int32(GoTest_TIME)
+	pb.Kind = NewGoTest_KIND(GoTest_TIME)
 	pb.RequiredField = initGoTestField()
 	pb.F_BoolRequired = Bool(true)
 	pb.F_Int32Required = Int32(3)
diff --git a/proto/equal_test.go b/proto/equal_test.go
index 9634771..e22c13b 100644
--- a/proto/equal_test.go
+++ b/proto/equal_test.go
@@ -49,7 +49,7 @@
 	{"equal empty", &pb.GoEnum{}, &pb.GoEnum{}, true},
 
 	{"one set field, one unset field", &pb.GoTestField{Label: String("foo")}, &pb.GoTestField{}, false},
-	{"one set field zero, one unset field", &pb.GoTest{Kind: Int32(0)}, &pb.GoTest{}, false},
+	{"one set field zero, one unset field", &pb.GoTest{Param: Int32(0)}, &pb.GoTest{}, false},
 	{"different set fields", &pb.GoTestField{Label: String("foo")}, &pb.GoTestField{Label: String("bar")}, false},
 	{"equal set", &pb.GoTestField{Label: String("foo")}, &pb.GoTestField{Label: String("foo")}, true},
 
diff --git a/proto/testdata/test.proto b/proto/testdata/test.proto
index b3f4bd6..70ff890 100644
--- a/proto/testdata/test.proto
+++ b/proto/testdata/test.proto
@@ -73,7 +73,7 @@
   };
 
   // Some typical parameters
-  required int32 Kind = 1;
+  required KIND Kind = 1;
   optional string Table = 2;
   optional int32 Param = 3;