From c2b8429cd1282296ecf2e24a805328fa85067034 Mon Sep 17 00:00:00 2001 From: Hyang-Ah Hana Kim Date: Thu, 3 Mar 2016 10:47:56 -0500 Subject: [PATCH] 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 --- bind/gen.go | 15 +++++++++++++++ bind/genjava.go | 2 +- bind/genobjc.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bind/gen.go b/bind/gen.go index 6d4cb4f..aac6842 100644 --- a/bind/gen.go +++ b/bind/gen.go @@ -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() +} diff --git a/bind/genjava.go b/bind/genjava.go index 0d70995..ffdba86 100644 --- a/bind/genjava.go +++ b/bind/genjava.go @@ -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()) diff --git a/bind/genobjc.go b/bind/genobjc.go index 66dd163..509c626 100644 --- a/bind/genobjc.go +++ b/bind/genobjc.go @@ -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())