google / j2objc

A Java to iOS Objective-C translation tool and runtime.
http://j2objc.org
Apache License 2.0
5.99k stars 965 forks source link

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

Open foens opened 9 years ago

foens commented 9 years ago

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:

package test;

public abstract class Maybe {
    private Maybe() {
    }

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

    private static final class Just<T> extends Maybe {
    }

    public static Maybe Nothing() {
        return Nothing;
    }

    private static final Maybe Nothing = new Nothing<Object>();

    private static final class Nothing<T> extends Maybe {
    }
}

This is a shortened example of the class Maybe.java from the Dropbox Java API, 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.

foens commented 9 years ago

Still a problem with 0.9.6

kstanger commented 9 years ago

This may be a good reason to switch to using "$" instead of "_" for delimiting inner classes.