Refine member scope for types with projections

Instead of erasing descriptors with conflicting substitution,
use invariant CapturedType(<projection>) as replacement for type parameter
within default member scope.

After substitution leave such types 'as is' everywhere except return types,
use common approximation for them.

 #KT-9294 In Progress
 #KT-5411 Fixed
 #KT-8647 Fixed

 #KT-9462 Fixed
 #KT-9893 Fixed
 #KT-7581 Fixed
 #KT-7296 In Progress
This commit is contained in:
Denis Zharkov
2015-12-22 14:02:55 +03:00
parent 365ff593f3
commit e2c02f825f
50 changed files with 655 additions and 60 deletions
@@ -7116,6 +7116,87 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
}
}
@TestMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ProjectionsScope extends AbstractDiagnosticsTest {
@TestMetadata("addAll.kt")
public void testAddAll() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/addAll.kt");
doTest(fileName);
}
public void testAllFilesPresentInProjectionsScope() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/generics/projectionsScope"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("extensionResultSubstitution.kt")
public void testExtensionResultSubstitution() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/extensionResultSubstitution.kt");
doTest(fileName);
}
@TestMetadata("kt7296.kt")
public void testKt7296() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/kt7296.kt");
doTest(fileName);
}
@TestMetadata("kt8647.kt")
public void testKt8647() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/kt8647.kt");
doTest(fileName);
}
@TestMetadata("lambdaArgument.kt")
public void testLambdaArgument() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/lambdaArgument.kt");
doTest(fileName);
}
@TestMetadata("MLOut.kt")
public void testMLOut() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/MLOut.kt");
doTest(fileName);
}
@TestMetadata("recursiveUpperBoundStar.kt")
public void testRecursiveUpperBoundStar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/recursiveUpperBoundStar.kt");
doTest(fileName);
}
@TestMetadata("starNullability.kt")
public void testStarNullability() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/starNullability.kt");
doTest(fileName);
}
@TestMetadata("starNullabilityRecursive.kt")
public void testStarNullabilityRecursive() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/starNullabilityRecursive.kt");
doTest(fileName);
}
@TestMetadata("superClass.kt")
public void testSuperClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/superClass.kt");
doTest(fileName);
}
@TestMetadata("typeParameterBounds.kt")
public void testTypeParameterBounds() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt");
doTest(fileName);
}
@TestMetadata("unsafeVarianceStar.kt")
public void testUnsafeVarianceStar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/generics/starProjections")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -9447,6 +9528,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("arrayOfStarParametrized.kt")
public void testArrayOfStarParametrized() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/arrayOfStarParametrized.kt");
doTest(fileName);
}
@TestMetadata("canDeclareIfSamAdapterIsInherited.kt")
public void testCanDeclareIfSamAdapterIsInherited() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/canDeclareIfSamAdapterIsInherited.kt");
@@ -31,6 +31,12 @@ import java.util.regex.Pattern;
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestWithStdLib {
@TestMetadata("addAllProjection.kt")
public void testAddAllProjection() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/addAllProjection.kt");
doTest(fileName);
}
public void testAllFilesPresentInTestsWithStdLib() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), true);
}
@@ -16,26 +16,25 @@
package org.jetbrains.kotlin.resolve.typeApproximation
import org.jetbrains.kotlin.test.KotlinLiteFixture
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.test.ConfigurationKind
import java.io.File
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.createCapturedType
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.KotlinLiteFixture
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.types.TypeProjectionImpl
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.Variance.*
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.calls.inference.createCapturedType
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypesIfNecessary
import java.util.ArrayList
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import java.io.File
import java.util.*
public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
@@ -85,7 +84,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
fun createTestSubstitutor(testSubstitution: Map<TypeParameterDescriptor, TypeProjection>): TypeSubstitutor {
val substitutionContext = testSubstitution.map {
val (typeParameter, typeProjection) = it
typeParameter.getTypeConstructor() to TypeProjectionImpl(createCapturedType(typeProjection))
typeParameter.typeConstructor to TypeProjectionImpl(createCapturedType(typeProjection))
}.toMap()
return TypeSubstitutor.create(substitutionContext)
}
@@ -111,7 +110,9 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
val typeWithCapturedType = typeSubstitutor.substituteWithoutApproximation(TypeProjectionImpl(INVARIANT, type!!))!!.getType()
val (lower, upper) = approximateCapturedTypes(typeWithCapturedType)
val substitution = approximateCapturedTypesIfNecessary(TypeProjectionImpl(INVARIANT, typeWithCapturedType))
val substitution =
approximateCapturedTypesIfNecessary(
TypeProjectionImpl(INVARIANT, typeWithCapturedType), approximateContravariant = false)
append(" ")
for (typeParameter in testSubstitution.keySet()) {