bind: fix error type
Errors was recently converted to use objects as representation instead
of strings. Issue golang/go#17073 exposed a few places that wasn't properly
updated. Fix them and add the test case from the the issue.
Fixes golang/go#17073
Change-Id: I0191993a8427d930540716407fc09032f282fc66
Reviewed-on: https://go-review.googlesource.com/29176
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/bind/genjava.go b/bind/genjava.go
index a36333d..9653563 100644
--- a/bind/genjava.go
+++ b/bind/genjava.go
@@ -308,7 +308,7 @@
// The error type is usually translated into an exception in
// Java, however the type can be exposed in other ways, such
// as an exported field.
- return "String"
+ return "java.lang.Exception"
}
switch T := T.(type) {
case *types.Basic:
@@ -906,6 +906,9 @@
}
func (g *JavaGen) jniSigType(T types.Type) string {
+ if isErrorType(T) {
+ return "Ljava/lang/Exception;"
+ }
switch T := T.(type) {
case *types.Basic:
switch T.Kind() {
diff --git a/bind/genobjc.go b/bind/genobjc.go
index 4a936bf..74045ff 100644
--- a/bind/genobjc.go
+++ b/bind/genobjc.go
@@ -964,7 +964,7 @@
func (g *objcGen) objcFieldType(t types.Type) string {
if isErrorType(t) {
- return "NSString*"
+ return "NSError*"
}
return g.objcType(t)
}
diff --git a/bind/java/SeqTest.java b/bind/java/SeqTest.java
index c81b682..6348e01 100644
--- a/bind/java/SeqTest.java
+++ b/bind/java/SeqTest.java
@@ -418,9 +418,9 @@
public void testErrorField() {
final String want = "an error message";
Node n = Testpkg.newNode("ErrTest");
- n.setErr(want);
- String got = n.getErr();
- assertEquals("want back the error message we set", want, got);
+ n.setErr(new Exception(want));
+ Exception got = n.getErr();
+ assertEquals("want back the error message we set", want, got.getMessage());
}
//test if we have JNI local reference table overflow error
diff --git a/bind/objc/SeqTest.m b/bind/objc/SeqTest.m
index 58519bf..7709131 100644
--- a/bind/objc/SeqTest.m
+++ b/bind/objc/SeqTest.m
@@ -294,6 +294,15 @@
XCTAssertTrue(GoTestpkgCallIError(num, NO, &error2), @"GoTestpkgCallIError(Number, NO) failed(%@); want success", error2);
}
+- (void)testErrorField {
+ NSString *want = @"an error message";
+ GoTestpkgNode *n = GoTestpkgNewNode(@"ErrTest");
+ n.err = [NSError errorWithDomain:@"SeqTest" code:1 userInfo:@{NSLocalizedDescriptionKey: want}];
+ NSError *got = n.err;
+ NSString *gotMsg = [got.userInfo valueForKey:NSLocalizedDescriptionKey];
+ XCTAssertEqualObjects(gotMsg, want, @"err = %@, want %@", gotMsg, want);
+}
+
- (void)testVar {
NSString *s = GoTestpkg.stringVar;
XCTAssertEqualObjects(s, @"a string var", @"GoTestpkg.StringVar = %@, want 'a string var'", s);
diff --git a/bind/testdata/issue12328.java.golden b/bind/testdata/issue12328.java.golden
index 52f0d70..fb92fc0 100644
--- a/bind/testdata/issue12328.java.golden
+++ b/bind/testdata/issue12328.java.golden
@@ -9,16 +9,16 @@
public final class T extends Seq.Proxy {
private T(go.Seq.Ref ref) { super(ref); }
- public final native String getErr();
- public final native void setErr(String v);
+ public final native java.lang.Exception getErr();
+ public final native void setErr(java.lang.Exception v);
@Override public boolean equals(Object o) {
if (o == null || !(o instanceof T)) {
return false;
}
T that = (T)o;
- String thisErr = getErr();
- String thatErr = that.getErr();
+ java.lang.Exception thisErr = getErr();
+ java.lang.Exception thatErr = that.getErr();
if (thisErr == null) {
if (thatErr != null) {
return false;
diff --git a/bind/testdata/issue12328.objc.h.golden b/bind/testdata/issue12328.objc.h.golden
index 6ab1b99..5e36fc8 100644
--- a/bind/testdata/issue12328.objc.h.golden
+++ b/bind/testdata/issue12328.objc.h.golden
@@ -16,8 +16,8 @@
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
-- (NSString*)err;
-- (void)setErr:(NSString*)v;
+- (NSError*)err;
+- (void)setErr:(NSError*)v;
@end
#endif
diff --git a/bind/testpkg/testpkg.go b/bind/testpkg/testpkg.go
index 0df80e4..a812e9e 100644
--- a/bind/testpkg/testpkg.go
+++ b/bind/testpkg/testpkg.go
@@ -533,3 +533,7 @@
}
func (ic *InitCaller) Init() {}
+
+type Issue17073 interface {
+ OnError(err error)
+}