bind: fallback to const.Value.String for pre go1.6

Fixes golang/go#14615

Change-Id: I75e130e5b7b2534660098907fa1f044390c01d01
Reviewed-on: https://go-review.googlesource.com/20164
Reviewed-by: Elias Naur <elias.naur@gmail.com>
This commit is contained in:
Hyang-Ah Hana Kim
2016-03-04 12:00:05 +00:00
parent 6fca37c69e
commit c2b8429cd1
3 changed files with 17 additions and 2 deletions
+15
View File
@@ -245,3 +245,18 @@ func paramName(params *types.Tuple, pos int) string {
}
return name
}
func constExactString(o *types.Const) string {
// TODO(hyangah): this is a temporary fix for golang.org/issues/14615.
// Clean this up when we can require at least go 1.6 or above.
type exactStringer interface {
ExactString() string
}
v := o.Val()
if v, ok := v.(exactStringer); ok {
return v.ExactString()
}
// TODO: warning?
return v.String()
}
+1 -1
View File
@@ -535,7 +535,7 @@ func (g *javaGen) genConst(o *types.Const) {
// TODO(hyangah): should const names use upper cases + "_"?
// TODO(hyangah): check invalid names.
jType := g.javaType(o.Type())
val := o.Val().ExactString()
val := constExactString(o)
switch b := o.Type().(*types.Basic); b.Kind() {
case types.Int64, types.UntypedInt:
i, exact := constant.Int64Val(o.Val())
+1 -1
View File
@@ -276,7 +276,7 @@ func (g *objcGen) genConstM(o *types.Const) {
g.Printf("const BOOL %s = %s;\n", cName, v)
case types.String, types.UntypedString:
g.Printf("NSString* const %s = @%s;\n", cName, o.Val().ExactString())
g.Printf("NSString* const %s = @%s;\n", cName, constExactString(o))
case types.Int, types.Int8, types.Int16, types.Int32:
g.Printf("const %s %s = %s;\n", objcType, cName, o.Val())