mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
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:
+15
@@ -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
@@ -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
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user