From 4b465afdfafe7568b4a43b66d42fe3592d99339b Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 20 Nov 2012 20:37:11 +0400 Subject: [PATCH] Saving order of super functions in SignaturesPropagation. --- .../SignaturesPropagation.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagation.java index a02abb43001..c6abb7a3f8e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagation.java @@ -20,21 +20,22 @@ import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.intellij.psi.HierarchicalMethodSignature; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import jet.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.CollectionClassMapping; import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper; +import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; +import java.util.*; public class SignaturesPropagation { public static JetType modifyReturnTypeAccordingToSuperMethods( @@ -43,10 +44,13 @@ public class SignaturesPropagation { @NotNull BindingTrace trace, @NotNull Function1 reportError ) { - Set typesFromSuperMethods = Sets.newHashSet(); - for (FunctionDescriptor superFunction : getSuperFunctionsForMethod(method, trace)) { - typesFromSuperMethods.add(superFunction.getReturnType()); - } + List typesFromSuperMethods = ContainerUtil.map(getSuperFunctionsForMethod(method, trace), + new Function() { + @Override + public JetType fun(FunctionDescriptor superFunction) { + return superFunction.getReturnType(); + } + }); return modifyReturnTypeAccordingToSuperMethods(autoType, typesFromSuperMethods, true, reportError); } @@ -73,6 +77,16 @@ public class SignaturesPropagation { // + method.getPsiMethod().getContainingClass(); } } + + // sorting for diagnostic stability + Collections.sort(superFunctions, new Comparator() { + @Override + public int compare(FunctionDescriptor fun1, FunctionDescriptor fun2) { + FqNameUnsafe fqName1 = DescriptorUtils.getFQName(fun1.getContainingDeclaration()); + FqNameUnsafe fqName2 = DescriptorUtils.getFQName(fun2.getContainingDeclaration()); + return fqName1.getFqName().compareTo(fqName2.getFqName()); + } + }); return superFunctions; } @@ -80,7 +94,7 @@ public class SignaturesPropagation { @NotNull private static JetType modifyReturnTypeAccordingToSuperMethods( @NotNull JetType autoType, - @NotNull Collection typesFromSuper, + @NotNull List typesFromSuper, boolean covariantPosition, @NotNull Function1 reportError ) { @@ -109,7 +123,7 @@ public class SignaturesPropagation { @NotNull private static List getTypeArgsOfReturnType( @NotNull JetType autoType, - @NotNull Collection typesFromSuper, + @NotNull List typesFromSuper, @NotNull Function1 reportError ) { TypeConstructor typeConstructor = autoType.getConstructor(); @@ -134,7 +148,7 @@ public class SignaturesPropagation { JetType argumentType = argument.getType(); List projectionsFromSuper = typeArgumentsFromSuper.get(parameter.getIndex()); - Collection argTypesFromSuper = getTypes(projectionsFromSuper); + List argTypesFromSuper = getTypes(projectionsFromSuper); boolean covariantPosition = effectiveProjectionKind == TypeCheckingProcedure.EnrichedProjectionKind.OUT; JetType type = modifyReturnTypeAccordingToSuperMethods(argumentType, argTypesFromSuper, covariantPosition, reportError); @@ -150,7 +164,7 @@ public class SignaturesPropagation { @NotNull List projectionsFromSuper, @NotNull Function1 reportError ) { - Set projectionKindsInSuper = Sets.newHashSet(); + Set projectionKindsInSuper = Sets.newLinkedHashSet(); for (TypeProjection projection : projectionsFromSuper) { projectionKindsInSuper.add(projection.getProjectionKind()); } @@ -242,7 +256,7 @@ public class SignaturesPropagation { private static boolean returnTypeMustBeNullable( @NotNull JetType autoType, - @NotNull Collection typesFromSuper, + @NotNull List typesFromSuper, boolean covariantPosition, @NotNull Function1 reportError ) { @@ -276,7 +290,7 @@ public class SignaturesPropagation { } @NotNull - private static ClassifierDescriptor getReturnTypeClassifier(@NotNull JetType autoType, @NotNull Collection typesFromSuper) { + private static ClassifierDescriptor getReturnTypeClassifier(@NotNull JetType autoType, @NotNull List typesFromSuper) { ClassifierDescriptor classifier = autoType.getConstructor().getDeclarationDescriptor(); if (!(classifier instanceof ClassDescriptor)) { assert classifier != null : "no declaration descriptor for type " + autoType;