google / google/j2objc

Translation of class where static method and inner class have same name causes redefinition compilation errors

Open
#446 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6k
Forks
999
Avg merge
19h 20m
Merged PRs (30d)
14

Description

I get the following errors:

```
In file included from ./build/j2objc-out//test/Maybe.m:6:
./build/j2objc-out/test/Maybe.h:30:12: error: redefinition of 'TestMaybe_Just' as different kind of symbol
@interface TestMaybe_Just : TestMaybe {
^
./build/j2objc-out/test/Maybe.h:24:30: note: previous definition is here
FOUNDATION_EXPORT TestMaybe *TestMaybe_Just();
^
./build/j2objc-out/test/Maybe.h:39:12: error: redefinition of 'TestMaybe_Nothing' as different kind of symbol
@interface TestMaybe_Nothing : TestMaybe {
^
./build/j2objc-out/test/Maybe.h:25:30: note: previous definition is here
FOUNDATION_EXPORT TestMaybe *TestMaybe_Nothing();
^
./build/j2objc-out//test/Maybe.m:19:10: error: reference to 'TestMaybe_Just' is ambiguous
return TestMaybe_Just();
^
./build/j2objc-out/test/Maybe.h:30:12: note: candidate found by name lookup is 'TestMaybe_Just'
@interface TestMaybe_Just : TestMaybe {
^
./build/j2objc-out/test/Maybe.h:24:30: note: candidate found by name lookup is 'TestMaybe_Just'
FOUNDATION_EXPORT TestMaybe *TestMaybe_Just();
^
./build/j2objc-out//test/Maybe.m:23:10: error: reference to 'TestMaybe_Nothing' is ambiguous
return TestMaybe_Nothing();
^
./build/j2objc-out/test/Maybe.h:39:12: note: candidate found by name lookup is 'TestMaybe_Nothing'
@interface TestMaybe_Nothing : TestMaybe {
^
./build/j2objc-out/test/Maybe.h:25:30: note: candidate found by name lookup is 'TestMaybe_Nothing'
FOUNDATION_EXPORT TestMaybe *TestMaybe_Nothing();
^
./build/j2objc-out//test/Maybe.m:28:29: error: reference to 'TestMaybe_Nothing' is ambiguous
TestMaybe_Nothing__ = [[TestMaybe_Nothing alloc] init];
^
./build/j2objc-out/test/Maybe.h:39:12: note: candidate found by name lookup is 'TestMaybe_Nothing'
@interface TestMaybe_Nothing : TestMaybe {
^
./build/j2objc-out/test/Maybe.h:25:30: note: candidate found by name lookup is 'TestMaybe_Nothing'
FOUNDATION_EXPORT TestMaybe *TestMaybe_Nothing();
^
./build/j2objc-out//test/Maybe.m:48:12: error: redefinition of 'TestMaybe_Just' as different kind of symbol
TestMaybe *TestMaybe_Just() {
^
./build/j2objc-out/test/Maybe.h:30:12: note: previous definition is here
@interface TestMaybe_Just : TestMaybe {
^
./build/j2objc-out//test/Maybe.m:50:12: error: reference to 'TestMaybe_Just' is ambiguous
return [[TestMaybe_Just alloc] init];
^
./build/j2objc-out/test/Maybe.h:30:12: note: candidate found by name lookup is 'TestMaybe_Just'
@interface TestMaybe_Just : TestMaybe {
^
./build/j2objc-out/test/Maybe.h:24:30: note: candidate found by name lookup is 'TestMaybe_Just'
FOUNDATION_EXPORT TestMaybe *TestMaybe_Just();
^
./build/j2objc-out//test/Maybe.m:53:12: error: redefinition of 'TestMaybe_Nothing' as different kind of symbol
TestMaybe *TestMaybe_Nothing() {
^
./build/j2objc-out/test/Maybe.h:39:12: note: previous definition is here
@interface TestMaybe_Nothing : TestMaybe {
^
./build/j2objc-out//test/Maybe.m:58:17: error: cannot find interface declaration for 'TestMaybe_Just' [-Werror]
@implementation TestMaybe_Just
^
./build/j2objc-out//test/Maybe.m:61:11: error: 'TestMaybe_Just' cannot use 'super' because it is a root class
return [super init];
^
./build/j2objc-out//test/Maybe.m:58:17: error: class 'TestMaybe_Just' defined without specifying a base class
[-Werror,-Wobjc-root-class]
@implementation TestMaybe_Just
^
./build/j2objc-out//test/Maybe.m:58:31: note: add a super class to fix this problem
@implementation TestMaybe_Just
^
: NSObject
./build/j2objc-out//test/Maybe.m:74:17: error: cannot find interface declaration for 'TestMaybe_Nothing' [-Werror]
@implementation TestMaybe_Nothing
^
./build/j2objc-out//test/Maybe.m:77:11: error: 'TestMaybe_Nothing' cannot use 'super' because it is a root class
return [super init];
^
./build/j2objc-out//test/Maybe.m:74:17: error: class 'TestMaybe_Nothing' defined without specifying a base class
[-Werror,-Wobjc-root-class]
@implementation TestMaybe_Nothing
^
./build/j2objc-out//test/Maybe.m:74:34: note: add a super class to fix this problem
@implementation TestMaybe_Nothing
^
: NSObject
14 errors generated.
```

when translating and compiling:

``` java
package test;

public abstract class Maybe {
private Maybe() {
}

public static Maybe Just() {
return new Just();
}

private static final class Just extends Maybe {
}

public static Maybe Nothing() {
return Nothing;
}

private static final Maybe Nothing = new Nothing();

private static final class Nothing extends Maybe {
}
}
```

This is a shortened example of the class [Maybe.java from the Dropbox Java API](http://grepcode.com/file/repo1.maven.org/maven2/com.dropbox.core/dropbox-core-sdk/1.7.7/com/dropbox/core/util/Maybe.java), which currently, cannot be compiled with j2objc-0.9.5. I know that j2objc-0.9.3 can correctly translate the source. I haven't tested with 0.9.4.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.