From 70293e6c50b29f82b10db17bebd48c96698c9392 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 16 Mar 2018 10:13:05 +0100 Subject: [PATCH] bind: skip incompatible constructors in ObjC bindings Fixes golang/go#21523 Change-Id: I1244e296ac4eeb0d10847e73216e4a25a3533292 Reviewed-on: https://go-review.googlesource.com/101115 Reviewed-by: Hyang-Ah Hana Kim --- bind/genobjc.go | 4 ++++ bind/testdata/testpkg/testpkg.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/bind/genobjc.go b/bind/genobjc.go index 8c8ff85..f3697ea 100644 --- a/bind/genobjc.go +++ b/bind/genobjc.go @@ -1161,6 +1161,10 @@ func (g *ObjcGen) genStructM(obj *types.TypeName, t *types.Struct) { cons := g.constructors[obj] if oinf == nil { for _, f := range cons { + if !g.isSigSupported(f.Type()) { + g.Printf("// skipped constructor %s.%s with unsupported parameter or return types\n\n", obj, f.Name()) + continue + } g.genInitM(obj, f) } } diff --git a/bind/testdata/testpkg/testpkg.go b/bind/testdata/testpkg/testpkg.go index e4ab40a..86739fd 100644 --- a/bind/testdata/testpkg/testpkg.go +++ b/bind/testdata/testpkg/testpkg.go @@ -9,6 +9,7 @@ package testpkg //go:generate gobind -lang=go -outdir=go_testpkg . //go:generate gobind -lang=java -outdir=. . import ( + "context" "errors" "fmt" "io/ioutil" @@ -609,3 +610,11 @@ func TestSIGPIPE() { type Testpkg interface{} func ClashingParameterFromOtherPackage(_ *secondpkg.Secondpkg) {} + +type MyStruct struct { +} + +// Test that constructors with incompatible signatures are ignored. +func NewMyStruct(ctx context.Context) *MyStruct { + return nil +}