diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java index ed9122d5327..28f4b601aab 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/sam/SingleAbstractMethodUtils.java @@ -190,7 +190,8 @@ public class SingleAbstractMethodUtils { original.getContainingDeclaration(), original.getAnnotations(), original.getName(), - CallableMemberDescriptor.Kind.SYNTHESIZED + CallableMemberDescriptor.Kind.SYNTHESIZED, + original ); FunctionInitializer initializer = new FunctionInitializer() { @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/SimpleFunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/SimpleFunctionDescriptorImpl.java index e04e6618a52..eac3c82898e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/SimpleFunctionDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/SimpleFunctionDescriptorImpl.java @@ -30,12 +30,29 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme private boolean isInline = false; + private final SimpleFunctionDescriptor originalOfSynthesized; // TODO replace with user data + public SimpleFunctionDescriptorImpl( @NotNull DeclarationDescriptor containingDeclaration, @NotNull List annotations, @NotNull Name name, - @NotNull Kind kind) { + @NotNull Kind kind + ) { + this(containingDeclaration, annotations, name, kind, null); + } + + public SimpleFunctionDescriptorImpl( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + @NotNull Name name, + @NotNull Kind kind, + @Nullable SimpleFunctionDescriptor originalOfSynthesized + ) { super(containingDeclaration, annotations, name, kind); + this.originalOfSynthesized = originalOfSynthesized; + if (originalOfSynthesized != null) { + assert kind == Kind.SYNTHESIZED; + } } private SimpleFunctionDescriptorImpl( @@ -45,6 +62,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme @NotNull Name name, @NotNull Kind kind) { super(containingDeclaration, original, annotations, name, kind); + originalOfSynthesized = null; } public SimpleFunctionDescriptorImpl initialize( @@ -100,4 +118,10 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme public boolean isInline() { return isInline; } + + // TODO replace with user data + @Nullable + public SimpleFunctionDescriptor getOriginalOfSynthesized() { + return originalOfSynthesized; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java index 4ad1bf23d46..d353d1f1ecf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java @@ -20,10 +20,12 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.intellij.openapi.util.Pair; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; @@ -183,6 +185,9 @@ public class OverridingUtil { } } + if (!isOverridableSynthesized(superDescriptor, subDescriptor)) { + return OverrideCompatibilityInfo.synthesizedAndDeclarationIncompatible(); + } } else { @@ -296,6 +301,89 @@ public class OverridingUtil { } } + private static boolean isOverridableSynthesized(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) { + if (subDescriptor instanceof PropertyDescriptor) { + return true; + } + + SimpleFunctionDescriptor superOriginal = getOriginalOfSamAdapterFunction((SimpleFunctionDescriptor) superDescriptor); + SimpleFunctionDescriptor subOriginal = getOriginalOfSamAdapterFunction((SimpleFunctionDescriptor) subDescriptor); + if (superOriginal == null || subOriginal == null) { // super or sub is/overrides DECLARATION + return subOriginal == null; // DECLARATION can override anything + } + + // inheritor if SYNTHESIZED can override inheritor of SYNTHESIZED if their originals have same erasure + return equalErasure(superOriginal, subOriginal); + } + + private static boolean equalErasure(@NotNull FunctionDescriptor fun1, @NotNull FunctionDescriptor fun2) { + List parameters1 = fun1.getValueParameters(); + List parameters2 = fun2.getValueParameters(); + + for (ValueParameterDescriptor param1 : parameters1) { + ValueParameterDescriptor param2 = parameters2.get(param1.getIndex()); + if (!TypeUtils.equalClasses(param2.getType(), param1.getType())) { + return false; + } + } + return true; + } + + // if function is or overrides declaration, returns null; otherwise, return original of sam adapter with substituted type parameters + @Nullable + private static SimpleFunctionDescriptor getOriginalOfSamAdapterFunction(@NotNull SimpleFunctionDescriptor callable) { + DeclarationDescriptor containingDeclaration = callable.getContainingDeclaration(); + if (!(containingDeclaration instanceof ClassDescriptor)) { + return null; + } + Pair declarationOrSynthesized = + getNearestDeclarationOrSynthesized(callable, ((ClassDescriptor) containingDeclaration).getDefaultType()); + + if (declarationOrSynthesized == null) { + return null; + } + + SimpleFunctionDescriptor fun = declarationOrSynthesized.first; + if (fun.getKind() != CallableMemberDescriptor.Kind.SYNTHESIZED) { + return null; + } + + SimpleFunctionDescriptor originalOfSynthesized = ((SimpleFunctionDescriptorImpl) fun.getOriginal()) + .getOriginalOfSynthesized(); + if (originalOfSynthesized == null) { + return null; + } + + return ((SimpleFunctionDescriptor) originalOfSynthesized.substitute(TypeSubstitutor.create(declarationOrSynthesized.second))); + } + + @Nullable + private static Pair getNearestDeclarationOrSynthesized( + @NotNull SimpleFunctionDescriptor samAdapter, + @NotNull JetType ownerType + ) { + if (samAdapter.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { + return Pair.create(samAdapter, ownerType); + } + for (CallableMemberDescriptor overridden : samAdapter.getOverriddenDescriptors()) { + ClassDescriptor containingClass = (ClassDescriptor) overridden.getContainingDeclaration(); + + for (JetType immediateSupertype : TypeUtils.getImmediateSupertypes(ownerType)) { + if (containingClass != immediateSupertype.getConstructor().getDeclarationDescriptor()) { + continue; + } + + Pair found = + getNearestDeclarationOrSynthesized((SimpleFunctionDescriptor) overridden, immediateSupertype); + if (found != null) { + return found; + } + } + + } + return null; + } + public static class OverrideCompatibilityInfo { public enum Result { @@ -356,6 +444,11 @@ public class OverridingUtil { return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "varOverriddenByVal"); // TODO } + @NotNull + public static OverrideCompatibilityInfo synthesizedAndDeclarationIncompatible() { + return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "synthesizedAndDeclarationIncompatible"); // TODO + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// private final Result overridable; diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.java new file mode 100644 index 00000000000..ae3f6895344 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.java @@ -0,0 +1,11 @@ +package test; + +public interface AdapterDoesntOverrideDeclaration { + public interface Super { + void foo(jet.Function0 r); + } + + public interface Sub extends Super { + void foo(Runnable r); + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.txt new file mode 100644 index 00000000000..ae35f9c4d02 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.txt @@ -0,0 +1,18 @@ +package test + +public trait AdapterDoesntOverrideDeclaration : java.lang.Object { + + public trait Sub : test.AdapterDoesntOverrideDeclaration.Super { + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super : java.lang.Object { + public abstract fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + } +} + +package AdapterDoesntOverrideDeclaration { + public /*synthesized*/ fun Super(/*0*/ function: ((() -> jet.Unit)?) -> jet.Unit): test.AdapterDoesntOverrideDeclaration.Super +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.java new file mode 100644 index 00000000000..26cb97e0900 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.java @@ -0,0 +1,11 @@ +package test; + +public interface InheritedAdapterAndDeclaration { + public interface Super { + void foo(Runnable r); + void foo(jet.Function0 r); + } + + public interface Sub extends Super { + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.txt new file mode 100644 index 00000000000..47c2df97ec1 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.txt @@ -0,0 +1,16 @@ +package test + +public trait InheritedAdapterAndDeclaration : java.lang.Object { + + public trait Sub : test.InheritedAdapterAndDeclaration.Super { + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super : java.lang.Object { + public abstract fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.java new file mode 100644 index 00000000000..48cca68f6a6 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.java @@ -0,0 +1,13 @@ +package test; + +import java.io.Closeable; + +public interface InheritedAmbiguousAdapters { + public interface Super { + void foo(Runnable r); + void foo(Closeable r); + } + + public interface Sub extends Super { + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.txt new file mode 100644 index 00000000000..4d1d2500067 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.txt @@ -0,0 +1,18 @@ +package test + +public trait InheritedAmbiguousAdapters : java.lang.Object { + + public trait Sub : test.InheritedAmbiguousAdapters.Super { + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.io.Closeable?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.io.Closeable?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.java new file mode 100644 index 00000000000..39f7f7efa46 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.java @@ -0,0 +1,14 @@ +package test; + +import java.io.Closeable; + +public interface InheritedAndOverriddenAmbiguousAdapters { + public interface Super { + void foo(Runnable r); + void foo(Closeable r); + } + + public interface Sub extends Super { + void foo(Runnable r); + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.txt new file mode 100644 index 00000000000..510814b316c --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.txt @@ -0,0 +1,18 @@ +package test + +public trait InheritedAndOverriddenAmbiguousAdapters : java.lang.Object { + + public trait Sub : test.InheritedAndOverriddenAmbiguousAdapters.Super { + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.io.Closeable?): jet.Unit + public abstract override /*1*/ fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.io.Closeable?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverridden.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverridden.java similarity index 100% rename from compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverridden.java rename to compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverridden.java diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverridden.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverridden.txt similarity index 100% rename from compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverridden.txt rename to compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverridden.txt diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverriddenAdapter.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverriddenAdapter.java similarity index 100% rename from compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverriddenAdapter.java rename to compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverriddenAdapter.java diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverriddenAdapter.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverriddenAdapter.txt similarity index 100% rename from compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverriddenAdapter.txt rename to compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverriddenAdapter.txt diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.java new file mode 100644 index 00000000000..1d0e88e2009 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.java @@ -0,0 +1,14 @@ +package test; + +public interface InheritedSameAdapters { + public interface Super1 { + void foo(Runnable r); + } + + public interface Super2 { + void foo(Runnable r); + } + + public interface Sub extends Super1, Super2 { + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.txt new file mode 100644 index 00000000000..c1482c7952d --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.txt @@ -0,0 +1,25 @@ +package test + +public trait InheritedSameAdapters : java.lang.Object { + + public trait Sub : test.InheritedSameAdapters.Super1, test.InheritedSameAdapters.Super2 { + public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super1 : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super2 : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } +} + +package InheritedSameAdapters { + public /*synthesized*/ fun Sub(/*0*/ function: (java.lang.Runnable?) -> jet.Unit): test.InheritedSameAdapters.Sub + public /*synthesized*/ fun Super1(/*0*/ function: (java.lang.Runnable?) -> jet.Unit): test.InheritedSameAdapters.Super1 + public /*synthesized*/ fun Super2(/*0*/ function: (java.lang.Runnable?) -> jet.Unit): test.InheritedSameAdapters.Super2 +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.java new file mode 100644 index 00000000000..061c3b40ac4 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.java @@ -0,0 +1,19 @@ +package test; + +import java.util.Comparator; + +public interface InheritedSameAdaptersWithSubstitution { + public interface Super1 { + void foo(Comparator r); + } + + public interface Super2 { + void foo(Comparator r); + } + + public interface Super2Substituted extends Super2 { + } + + public interface Sub extends Super1, Super2Substituted { + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.txt new file mode 100644 index 00000000000..74c79f58c27 --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.txt @@ -0,0 +1,31 @@ +package test + +public trait InheritedSameAdaptersWithSubstitution : java.lang.Object { + + public trait Sub : test.InheritedSameAdaptersWithSubstitution.Super1, test.InheritedSameAdaptersWithSubstitution.Super2Substituted { + public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: ((jet.String, jet.String) -> jet.Int)?): jet.Unit + public abstract override /*2*/ /*fake_override*/ fun foo(/*0*/ p0: java.util.Comparator?): jet.Unit + } + + public trait Super1 : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: ((jet.String, jet.String) -> jet.Int)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.util.Comparator?): jet.Unit + } + + public trait Super2 : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: ((T, T) -> jet.Int)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.util.Comparator?): jet.Unit + } + + public trait Super2Substituted : test.InheritedSameAdaptersWithSubstitution.Super2 { + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: ((jet.String, jet.String) -> jet.Int)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.util.Comparator?): jet.Unit + } +} + +package InheritedSameAdaptersWithSubstitution { + public /*synthesized*/ fun Sub(/*0*/ function: (java.util.Comparator?) -> jet.Unit): test.InheritedSameAdaptersWithSubstitution.Sub + public /*synthesized*/ fun Super1(/*0*/ function: (java.util.Comparator?) -> jet.Unit): test.InheritedSameAdaptersWithSubstitution.Super1 + public /*synthesized*/ fun Super2(/*0*/ function: (java.util.Comparator?) -> jet.Unit): test.InheritedSameAdaptersWithSubstitution.Super2 + public /*synthesized*/ fun Super2Substituted(/*0*/ function: (java.util.Comparator?) -> jet.Unit): test.InheritedSameAdaptersWithSubstitution.Super2Substituted +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedSimple.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSimple.java similarity index 98% rename from compiler/testData/loadJava/compiledJava/sam/adapters/InheritedSimple.java rename to compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSimple.java index 66c7a3c1988..47dfb45759e 100644 --- a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedSimple.java +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSimple.java @@ -7,4 +7,4 @@ public interface InheritedSimple { public interface Sub extends Super { } -} \ No newline at end of file +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/InheritedSimple.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSimple.txt similarity index 100% rename from compiler/testData/loadJava/compiledJava/sam/adapters/InheritedSimple.txt rename to compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSimple.txt diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.java b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.java new file mode 100644 index 00000000000..08409d2c53d --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.java @@ -0,0 +1,14 @@ +package test; + +import java.io.Closeable; + +public interface OverriddenAmbiguousAdapters { + public interface Super { + void foo(Runnable r); + void foo(Closeable r); + } + + public interface Sub extends Super { + void foo(jet.Function0 r); + } +} diff --git a/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.txt b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.txt new file mode 100644 index 00000000000..cd9e7ce35ac --- /dev/null +++ b/compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.txt @@ -0,0 +1,17 @@ +package test + +public trait OverriddenAmbiguousAdapters : java.lang.Object { + + public trait Sub : test.OverriddenAmbiguousAdapters.Super { + public abstract override /*2*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.io.Closeable?): jet.Unit + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } + + public trait Super : java.lang.Object { + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract /*synthesized*/ fun foo(/*0*/ p0: (() -> jet.Unit)?): jet.Unit + public abstract fun foo(/*0*/ p0: java.io.Closeable?): jet.Unit + public abstract fun foo(/*0*/ p0: java.lang.Runnable?): jet.Unit + } +} diff --git a/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin.txt b/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin.txt new file mode 100644 index 00000000000..204e3bceb3a --- /dev/null +++ b/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin.txt @@ -0,0 +1,17 @@ +package test + +public final class Sub : test.Super { + public constructor Sub() + internal open override /*1*/ /*fake_override*/ fun foo(/*0*/ r: (() -> jet.Unit)?): jet.Unit + internal open override /*1*/ /*fake_override*/ fun foo(/*0*/ r: (() -> jet.Unit)?): jet.Unit + internal open override /*1*/ /*fake_override*/ fun foo(/*0*/ r: java.io.Closeable?): jet.Unit + internal open override /*1*/ /*fake_override*/ fun foo(/*0*/ r: java.lang.Runnable?): jet.Unit +} + +public open class Super : java.lang.Object { + public constructor Super() + public/*package*/ open /*synthesized*/ fun foo(/*0*/ r: (() -> jet.Unit)?): jet.Unit + public/*package*/ open /*synthesized*/ fun foo(/*0*/ r: (() -> jet.Unit)?): jet.Unit + public/*package*/ open fun foo(/*0*/ r: java.io.Closeable?): jet.Unit + public/*package*/ open fun foo(/*0*/ r: java.lang.Runnable?): jet.Unit +} diff --git a/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin/Sub.kt b/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin/Sub.kt new file mode 100644 index 00000000000..697db35654f --- /dev/null +++ b/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin/Sub.kt @@ -0,0 +1,4 @@ +package test + +public class Sub: Super() { +} diff --git a/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin/Super.java b/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin/Super.java new file mode 100644 index 00000000000..fd4102991bd --- /dev/null +++ b/compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin/Super.java @@ -0,0 +1,8 @@ +package test; + +import java.io.Closeable; + +public class Super { + void foo(Runnable r); + void foo(Closeable r); +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index 1a3b36ce16c..b9680c61ef3 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -1201,6 +1201,7 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { } @TestMetadata("compiler/testData/loadJava/compiledJava/sam/adapters") + @InnerTestClasses({Adapters.Inheritance.class}) public static class Adapters extends AbstractLoadJavaTest { public void testAllFilesPresentInAdapters() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJava/sam/adapters"), Pattern.compile("^(.+)\\.java$"), true); @@ -1226,21 +1227,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/DeepSamLoop.java"); } - @TestMetadata("InheritedOverridden.java") - public void testInheritedOverridden() throws Exception { - doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverridden.java"); - } - - @TestMetadata("InheritedOverriddenAdapter.java") - public void testInheritedOverriddenAdapter() throws Exception { - doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/InheritedOverriddenAdapter.java"); - } - - @TestMetadata("InheritedSimple.java") - public void testInheritedSimple() throws Exception { - doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/InheritedSimple.java"); - } - @TestMetadata("NonTrivialFunctionType.java") public void testNonTrivialFunctionType() throws Exception { doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/NonTrivialFunctionType.java"); @@ -1271,12 +1257,76 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/TypeParameterOfOuterClass.java"); } + @TestMetadata("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance") + public static class Inheritance extends AbstractLoadJavaTest { + @TestMetadata("AdapterDoesntOverrideDeclaration.java") + public void testAdapterDoesntOverrideDeclaration() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/AdapterDoesntOverrideDeclaration.java"); + } + + public void testAllFilesPresentInInheritance() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance"), Pattern.compile("^(.+)\\.java$"), true); + } + + @TestMetadata("InheritedAdapterAndDeclaration.java") + public void testInheritedAdapterAndDeclaration() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAdapterAndDeclaration.java"); + } + + @TestMetadata("InheritedAmbiguousAdapters.java") + public void testInheritedAmbiguousAdapters() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAmbiguousAdapters.java"); + } + + @TestMetadata("InheritedAndOverriddenAmbiguousAdapters.java") + public void testInheritedAndOverriddenAmbiguousAdapters() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedAndOverriddenAmbiguousAdapters.java"); + } + + @TestMetadata("InheritedOverridden.java") + public void testInheritedOverridden() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverridden.java"); + } + + @TestMetadata("InheritedOverriddenAdapter.java") + public void testInheritedOverriddenAdapter() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedOverriddenAdapter.java"); + } + + @TestMetadata("InheritedSameAdapters.java") + public void testInheritedSameAdapters() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdapters.java"); + } + + @TestMetadata("InheritedSameAdaptersWithSubstitution.java") + public void testInheritedSameAdaptersWithSubstitution() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSameAdaptersWithSubstitution.java"); + } + + @TestMetadata("InheritedSimple.java") + public void testInheritedSimple() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/InheritedSimple.java"); + } + + @TestMetadata("OverriddenAmbiguousAdapters.java") + public void testOverriddenAmbiguousAdapters() throws Exception { + doTestCompiledJava("compiler/testData/loadJava/compiledJava/sam/adapters/inheritance/OverriddenAmbiguousAdapters.java"); + } + + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("Adapters"); + suite.addTestSuite(Adapters.class); + suite.addTestSuite(Inheritance.class); + return suite; + } } public static Test innerSuite() { TestSuite suite = new TestSuite("Sam"); suite.addTestSuite(Sam.class); - suite.addTestSuite(Adapters.class); + suite.addTest(Adapters.innerSuite()); return suite; } } @@ -1422,6 +1472,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/javaAgainstKotlin/samAdapters"), Pattern.compile("^(.+)\\.txt$"), true); } + @TestMetadata("InheritAmbguousSamAdaptersInKotlin.txt") + public void testInheritAmbguousSamAdaptersInKotlin() throws Exception { + doTestJavaAgainstKotlin("compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritAmbguousSamAdaptersInKotlin.txt"); + } + @TestMetadata("InheritSamAdapterInKotlin.txt") public void testInheritSamAdapterInKotlin() throws Exception { doTestJavaAgainstKotlin("compiler/testData/loadJava/javaAgainstKotlin/samAdapters/InheritSamAdapterInKotlin.txt");