Skip to content

Commit

Permalink
bind: ignore type aliases to basic types
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond committed Jan 25, 2019
1 parent ca3c581 commit c5d4a48
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 2 deletions.
1 change: 1 addition & 0 deletions bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var tests = []string{
"testdata/issue10788.go",
"testdata/issue12328.go",
"testdata/issue12403.go",
"testdata/issue29559.go",
"testdata/keywords.go",
"testdata/try.go",
"testdata/vars.go",
Expand Down
10 changes: 8 additions & 2 deletions bind/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ func (g *Generator) Init() {
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})
Expand Down Expand Up @@ -180,7 +183,10 @@ func (g *Generator) Init() {
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)})
}
Expand Down
5 changes: 5 additions & 0 deletions bind/testdata/issue29559.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package issue29559

type AString = string

func TakesAString(s AString) {}
28 changes: 28 additions & 0 deletions bind/testdata/issue29559.go.golden
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions bind/testdata/issue29559.java.c.golden
Original file line number Diff line number Diff line change
@@ -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);
}

25 changes: 25 additions & 0 deletions bind/testdata/issue29559.java.golden
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions bind/testdata/issue29559.java.h.golden
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions bind/testdata/issue29559.objc.go.h.golden
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions bind/testdata/issue29559.objc.h.golden
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions bind/testdata/issue29559.objc.m.golden
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit c5d4a48

Please sign in to comment.