bind: ignore type aliases to basic types

Fixes golang/go#29559

Change-Id: Iffaac239e5c9a9e53f4e292b4d9bf669d5084e1f
GitHub-Last-Rev: c5d4a4823d2bf60fa7bff09ab7bbdc9235c49d67
GitHub-Pull-Request: golang/mobile#25
Reviewed-on: https://go-review.googlesource.com/c/159417
Reviewed-by: Elias Naur <mail@eliasnaur.com>
diff --git a/bind/bind_test.go b/bind/bind_test.go
index 7314bd1..6732ff3 100644
--- a/bind/bind_test.go
+++ b/bind/bind_test.go
@@ -39,6 +39,7 @@
 	"testdata/issue10788.go",
 	"testdata/issue12328.go",
 	"testdata/issue12403.go",
+	"testdata/issue29559.go",
 	"testdata/keywords.go",
 	"testdata/try.go",
 	"testdata/vars.go",
diff --git a/bind/gen.go b/bind/gen.go
index b796893..beef4b4 100644
--- a/bind/gen.go
+++ b/bind/gen.go
@@ -146,7 +146,10 @@
 					g.funcs = append(g.funcs, obj)
 				}
 			case *types.TypeName:
-				named := obj.Type().(*types.Named)
+				named, ok := obj.Type().(*types.Named)
+				if !ok {
+					continue
+				}
 				switch t := named.Underlying().(type) {
 				case *types.Struct:
 					g.structs = append(g.structs, structInfo{obj, t})
@@ -180,7 +183,10 @@
 				continue
 			}
 			if obj, ok := obj.(*types.TypeName); ok {
-				named := obj.Type().(*types.Named)
+				named, ok := obj.Type().(*types.Named)
+				if !ok {
+					continue
+				}
 				if t, ok := named.Underlying().(*types.Interface); ok {
 					g.allIntf = append(g.allIntf, interfaceInfo{obj, t, makeIfaceSummary(t)})
 				}
diff --git a/bind/testdata/issue29559.go b/bind/testdata/issue29559.go
new file mode 100644
index 0000000..597847d
--- /dev/null
+++ b/bind/testdata/issue29559.go
@@ -0,0 +1,5 @@
+package issue29559
+
+type AString = string
+
+func TakesAString(s AString) {}
diff --git a/bind/testdata/issue29559.go.golden b/bind/testdata/issue29559.go.golden
new file mode 100644
index 0000000..1d88aea
--- /dev/null
+++ b/bind/testdata/issue29559.go.golden
@@ -0,0 +1,28 @@
+// Package main is an autogenerated binder stub for package issue29559.
+//   gobind -lang=go issue29559
+//
+// File is generated by gobind. Do not edit.
+package main
+
+/*
+#include <stdlib.h>
+#include <stdint.h>
+#include "seq.h"
+#include "issue29559.h"
+
+*/
+import "C"
+
+import (
+	_seq "golang.org/x/mobile/bind/seq"
+	"issue29559"
+)
+
+// suppress the error if seq ends up unused
+var _ = _seq.FromRefNum
+
+//export proxyissue29559__TakesAString
+func proxyissue29559__TakesAString(param_s C.nstring) {
+	_param_s := decodeString(param_s)
+	issue29559.TakesAString(_param_s)
+}
diff --git a/bind/testdata/issue29559.java.c.golden b/bind/testdata/issue29559.java.c.golden
new file mode 100644
index 0000000..8cd552c
--- /dev/null
+++ b/bind/testdata/issue29559.java.c.golden
@@ -0,0 +1,23 @@
+// JNI functions for the Go <=> Java bridge.
+//   gobind -lang=java issue29559
+//
+// File is generated by gobind. Do not edit.
+
+#include <android/log.h>
+#include <stdint.h>
+#include "seq.h"
+#include "_cgo_export.h"
+#include "issue29559.h"
+
+
+JNIEXPORT void JNICALL
+Java_issue29559_Issue29559__1init(JNIEnv *env, jclass _unused) {
+    jclass clazz;
+}
+
+JNIEXPORT void JNICALL
+Java_issue29559_Issue29559_takesAString(JNIEnv* env, jclass _clazz, jstring s) {
+    nstring _s = go_seq_from_java_string(env, s);
+    proxyissue29559__TakesAString(_s);
+}
+
diff --git a/bind/testdata/issue29559.java.golden b/bind/testdata/issue29559.java.golden
new file mode 100644
index 0000000..946e4b9
--- /dev/null
+++ b/bind/testdata/issue29559.java.golden
@@ -0,0 +1,25 @@
+// Java class issue29559.Issue29559 is a proxy for talking to a Go program.
+//   gobind -lang=java issue29559
+//
+// File is generated by gobind. Do not edit.
+package issue29559;
+
+import go.Seq;
+
+public abstract class Issue29559 {
+    static {
+        Seq.touch(); // for loading the native library
+        _init();
+    }
+    
+    private Issue29559() {} // uninstantiable
+    
+    // touch is called from other bound packages to initialize this package
+    public static void touch() {}
+    
+    private static native void _init();
+    
+    
+    
+    public static native void takesAString(String s);
+}
diff --git a/bind/testdata/issue29559.java.h.golden b/bind/testdata/issue29559.java.h.golden
new file mode 100644
index 0000000..a931ee0
--- /dev/null
+++ b/bind/testdata/issue29559.java.h.golden
@@ -0,0 +1,11 @@
+// JNI function headers for the Go <=> Java bridge.
+//   gobind -lang=java issue29559
+//
+// File is generated by gobind. Do not edit.
+
+#ifndef __Issue29559_H__
+#define __Issue29559_H__
+
+#include <jni.h>
+
+#endif
diff --git a/bind/testdata/issue29559.objc.go.h.golden b/bind/testdata/issue29559.objc.go.h.golden
new file mode 100644
index 0000000..93771b4
--- /dev/null
+++ b/bind/testdata/issue29559.objc.go.h.golden
@@ -0,0 +1,11 @@
+// Objective-C API for talking to issue29559 Go package.
+//   gobind -lang=objc issue29559
+//
+// File is generated by gobind. Do not edit.
+
+#ifndef __GO_issue29559_H__
+#define __GO_issue29559_H__
+
+#include <stdint.h>
+#include <objc/objc.h>
+#endif
diff --git a/bind/testdata/issue29559.objc.h.golden b/bind/testdata/issue29559.objc.h.golden
new file mode 100644
index 0000000..412eed1
--- /dev/null
+++ b/bind/testdata/issue29559.objc.h.golden
@@ -0,0 +1,15 @@
+// Objective-C API for talking to issue29559 Go package.
+//   gobind -lang=objc issue29559
+//
+// File is generated by gobind. Do not edit.
+
+#ifndef __Issue29559_H__
+#define __Issue29559_H__
+
+@import Foundation;
+#include "Universe.objc.h"
+
+
+FOUNDATION_EXPORT void Issue29559TakesAString(NSString* s);
+
+#endif
diff --git a/bind/testdata/issue29559.objc.m.golden b/bind/testdata/issue29559.objc.m.golden
new file mode 100644
index 0000000..c01628c
--- /dev/null
+++ b/bind/testdata/issue29559.objc.m.golden
@@ -0,0 +1,19 @@
+// Objective-C API for talking to issue29559 Go package.
+//   gobind -lang=objc issue29559
+//
+// File is generated by gobind. Do not edit.
+
+#include <Foundation/Foundation.h>
+#include "seq.h"
+#include "_cgo_export.h"
+#include "Issue29559.objc.h"
+
+
+void Issue29559TakesAString(NSString* s) {
+	nstring _s = go_seq_from_objc_string(s);
+	proxyissue29559__TakesAString(_s);
+}
+
+__attribute__((constructor)) static void init() {
+	init_seq();
+}