Skip to content

Commit

Permalink
Fixed a compile error when calling default methods from another modul…
Browse files Browse the repository at this point in the history
…e due to the delegate methods being marked synthetic

Fixes #56
  • Loading branch information
luontola committed Jul 8, 2015
1 parent e2156af commit 2f2e124
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ optimizations to that mechanism may break Retrolambda.
Version History
---------------

### Upcoming

- Fixed a compile error when calling default methods from another module
([Issue #56](https://github.com/orfjackal/retrolambda/issues/56))

### Retrolambda 2.0.3 (2015-06-07)

- Fixed Retrolambda generating stack map frames for Java 5 bytecode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2013-2014 Esko Luontola <www.orfjackal.net>
// Copyright © 2013-2015 Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0

Expand All @@ -19,4 +19,20 @@ public static int callLambda() throws Exception {
public static List<String> useLambdaOfImportedType(List<String> items) {
return Lists.transform(items, String::toUpperCase);
}

public interface Interface {
default String defaultMethod() {
return "default";
}
}

public static class Implementer implements Interface {
}

public static class Overrider implements Interface {
@Override
public String defaultMethod() {
return "overridden";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ default Callable<String> captureThis() {
*/
@Test
public void default_methods_with_lambdas_in_another_package() throws Exception {
assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.8f)));

UsesLambdasInAnotherPackage obj = new UsesLambdasInAnotherPackage() {
};
assertThat(obj.stateless().call(), is("foo"));
Expand All @@ -480,6 +482,34 @@ public void default_methods_with_lambdas_in_another_package() throws Exception {
obj.getClass().getDeclaredMethods(), arrayWithSize(2));
}

/**
* Though we use {@link InMainSources}, because the Retrolambda Maven plugin
* processes the main sources separately from the test sources, the effect is
* the same as if they were in another module.
*/
@Test
public void calling_default_methods_from_another_module_through_interface() {
InMainSources.Interface implementer = new InMainSources.Implementer();
assertThat(implementer.defaultMethod(), is("default"));

InMainSources.Interface overrider = new InMainSources.Overrider();
assertThat(overrider.defaultMethod(), is("overridden"));
}

/**
* Fixes issue of the generated delegate methods being marked as synthetic,
* in which case the Java compiler causes "error: cannot find symbol"
* for direct calls to those methods.
*/
@Test
public void calling_default_methods_from_another_module_through_class() {
InMainSources.Implementer implementer = new InMainSources.Implementer();
assertThat(implementer.defaultMethod(), is("default"));

InMainSources.Overrider overrider = new InMainSources.Overrider();
assertThat(overrider.defaultMethod(), is("overridden"));
}


/**
* We're unable to backport default methods if we cannot modify the interface,
Expand Down Expand Up @@ -553,7 +583,7 @@ default void annotatedDefaultMethod() {
}

@SomeAnnotation(4)
public static void annotatedStaticMethod() {
static void annotatedStaticMethod() {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void visit(int version, int access, String name, String signature, String
public void visitEnd() {
for (MethodInfo method : analyzer.getDefaultMethods(Type.getObjectType(className))) {
Bytecode.generateDelegateMethod(cv,
ACC_PUBLIC | ACC_SYNTHETIC,
ACC_PUBLIC,
method.toMethodRef().toHandle(),
method.getDefaultMethodImpl().toHandle());
}
Expand Down

0 comments on commit 2f2e124

Please sign in to comment.