Skip to content

Commit c5d4a48

Browse files
committed
bind: ignore type aliases to basic types
1 parent ca3c581 commit c5d4a48

10 files changed

+146
-2
lines changed

bind/bind_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var tests = []string{
3939
"testdata/issue10788.go",
4040
"testdata/issue12328.go",
4141
"testdata/issue12403.go",
42+
"testdata/issue29559.go",
4243
"testdata/keywords.go",
4344
"testdata/try.go",
4445
"testdata/vars.go",

bind/gen.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ func (g *Generator) Init() {
146146
g.funcs = append(g.funcs, obj)
147147
}
148148
case *types.TypeName:
149-
named := obj.Type().(*types.Named)
149+
named, ok := obj.Type().(*types.Named)
150+
if !ok {
151+
continue
152+
}
150153
switch t := named.Underlying().(type) {
151154
case *types.Struct:
152155
g.structs = append(g.structs, structInfo{obj, t})
@@ -180,7 +183,10 @@ func (g *Generator) Init() {
180183
continue
181184
}
182185
if obj, ok := obj.(*types.TypeName); ok {
183-
named := obj.Type().(*types.Named)
186+
named, ok := obj.Type().(*types.Named)
187+
if !ok {
188+
continue
189+
}
184190
if t, ok := named.Underlying().(*types.Interface); ok {
185191
g.allIntf = append(g.allIntf, interfaceInfo{obj, t, makeIfaceSummary(t)})
186192
}

bind/testdata/issue29559.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package issue29559
2+
3+
type AString = string
4+
5+
func TakesAString(s AString) {}

bind/testdata/issue29559.go.golden

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Package main is an autogenerated binder stub for package issue29559.
2+
// gobind -lang=go issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
package main
6+
7+
/*
8+
#include <stdlib.h>
9+
#include <stdint.h>
10+
#include "seq.h"
11+
#include "issue29559.h"
12+
13+
*/
14+
import "C"
15+
16+
import (
17+
_seq "golang.org/x/mobile/bind/seq"
18+
"issue29559"
19+
)
20+
21+
// suppress the error if seq ends up unused
22+
var _ = _seq.FromRefNum
23+
24+
//export proxyissue29559__TakesAString
25+
func proxyissue29559__TakesAString(param_s C.nstring) {
26+
_param_s := decodeString(param_s)
27+
issue29559.TakesAString(_param_s)
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// JNI functions for the Go <=> Java bridge.
2+
// gobind -lang=java issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
6+
#include <android/log.h>
7+
#include <stdint.h>
8+
#include "seq.h"
9+
#include "_cgo_export.h"
10+
#include "issue29559.h"
11+
12+
13+
JNIEXPORT void JNICALL
14+
Java_issue29559_Issue29559__1init(JNIEnv *env, jclass _unused) {
15+
jclass clazz;
16+
}
17+
18+
JNIEXPORT void JNICALL
19+
Java_issue29559_Issue29559_takesAString(JNIEnv* env, jclass _clazz, jstring s) {
20+
nstring _s = go_seq_from_java_string(env, s);
21+
proxyissue29559__TakesAString(_s);
22+
}
23+

bind/testdata/issue29559.java.golden

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Java class issue29559.Issue29559 is a proxy for talking to a Go program.
2+
// gobind -lang=java issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
package issue29559;
6+
7+
import go.Seq;
8+
9+
public abstract class Issue29559 {
10+
static {
11+
Seq.touch(); // for loading the native library
12+
_init();
13+
}
14+
15+
private Issue29559() {} // uninstantiable
16+
17+
// touch is called from other bound packages to initialize this package
18+
public static void touch() {}
19+
20+
private static native void _init();
21+
22+
23+
24+
public static native void takesAString(String s);
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// JNI function headers for the Go <=> Java bridge.
2+
// gobind -lang=java issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
6+
#ifndef __Issue29559_H__
7+
#define __Issue29559_H__
8+
9+
#include <jni.h>
10+
11+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Objective-C API for talking to issue29559 Go package.
2+
// gobind -lang=objc issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
6+
#ifndef __GO_issue29559_H__
7+
#define __GO_issue29559_H__
8+
9+
#include <stdint.h>
10+
#include <objc/objc.h>
11+
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Objective-C API for talking to issue29559 Go package.
2+
// gobind -lang=objc issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
6+
#ifndef __Issue29559_H__
7+
#define __Issue29559_H__
8+
9+
@import Foundation;
10+
#include "Universe.objc.h"
11+
12+
13+
FOUNDATION_EXPORT void Issue29559TakesAString(NSString* s);
14+
15+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Objective-C API for talking to issue29559 Go package.
2+
// gobind -lang=objc issue29559
3+
//
4+
// File is generated by gobind. Do not edit.
5+
6+
#include <Foundation/Foundation.h>
7+
#include "seq.h"
8+
#include "_cgo_export.h"
9+
#include "Issue29559.objc.h"
10+
11+
12+
void Issue29559TakesAString(NSString* s) {
13+
nstring _s = go_seq_from_objc_string(s);
14+
proxyissue29559__TakesAString(_s);
15+
}
16+
17+
__attribute__((constructor)) static void init() {
18+
init_seq();
19+
}

0 commit comments

Comments
 (0)