Details
Description
Having a class with a property and then explicitly defining the setter but giving it a return value (common for Builder classes) will compile fine with groovyc without joint compiling. When using joint compiling the java stubs generated are invalid. They end up with multiple setters - one normal void setter and one with the return value. Obviously this is not valid code. See the following example:
class SetterWithReturn {
String foo
def String bar
SetterWithReturn setFoo(String foo) { this.foo = foo; return this; }
SetterWithReturn setBar(String bar) { this.bar = bar; return this; }
}
public class SetterWithReturnClient { { new SetterWithReturn(); } }
Here is the error the compiler gives:
C:\IdeaProjects\groovy-bugs>groovyc -j src\main\groovy\SetterWithReturn.groovy src\main\java\SetterWithReturnC lient.java org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Compile error during compilation with javac. C:\DOCUME~1\schnee13\LOCALS~1\Temp\groovy-generated-1842144177968937199-java-source\SetterWithReturn.java:22: setFoo(java.lang.String) is already defined in SetterWithReturn public SetterWithReturn setFoo(java.lang.String foo) { return (SetterWithReturn)null;} ^ C:\DOCUME~1\schnee13\LOCALS~1\Temp\groovy-generated-1842144177968937199-java-source\SetterWithReturn.java:23: setBar(java.lang.String) is already defined in SetterWithReturn public SetterWithReturn setBar(java.lang.String bar) { return (SetterWithReturn)null;} ^ 2 errors 1 error
Looks like Groovy actually produces both the void and returning type in its generated bytecode and doesn't complain. It seems to always pick the non-void method but that could be VM-specific behavior. I guess we should fix that behavior and then the joint compilation may just work if the same compiler visitor is involved.