FIR: Fix incorrect handling bare types when subject is type alias
^KT-39043 Fixed
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
|||||||
|
sealed class A<out T> {
|
||||||
|
class B<out T1>(val x: T1) : A<T1>()
|
||||||
|
class C<out T2>(val y: T2) : A<T2>()
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias TA = A<CharSequence>
|
||||||
|
|
||||||
|
fun bar(): TA = TODO()
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
when (val a = bar()) {
|
||||||
|
is A.B -> a.x.length
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
FILE: bareWithSubjectTypeAlias.kt
|
||||||
|
public sealed class A<out T> : R|kotlin/Any| {
|
||||||
|
private constructor<out T>(): R|A<T>| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class B<out T1> : R|A<T1>| {
|
||||||
|
public constructor<out T1>(x: R|T1|): R|A.B<T1>| {
|
||||||
|
super<R|A<T1>|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final val x: R|T1| = R|<local>/x|
|
||||||
|
public get(): R|T1|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class C<out T2> : R|A<T2>| {
|
||||||
|
public constructor<out T2>(y: R|T2|): R|A.C<T2>| {
|
||||||
|
super<R|A<T2>|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final val y: R|T2| = R|<local>/y|
|
||||||
|
public get(): R|T2|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final typealias TA = R|A<kotlin/CharSequence>|
|
||||||
|
public final fun bar(): R|TA| {
|
||||||
|
^bar R|kotlin/TODO|()
|
||||||
|
}
|
||||||
|
public final fun foo(): R|kotlin/Unit| {
|
||||||
|
when (lval a: R|TA| = R|/bar|()) {
|
||||||
|
($subj$ is R|A.B<kotlin/CharSequence>|) -> {
|
||||||
|
R|<local>/a|.R|FakeOverride</A.B.x: R|kotlin/CharSequence|>|.R|kotlin/CharSequence.length|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Generated
+18
@@ -2241,6 +2241,24 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/types")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Types extends AbstractFirDiagnosticsTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInTypes() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("bareWithSubjectTypeAlias.kt")
|
||||||
|
public void testBareWithSubjectTypeAlias() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithSubjectTypeAlias.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/visibility")
|
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/visibility")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+18
@@ -2241,6 +2241,24 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/types")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Types extends AbstractFirDiagnosticsWithLightTreeTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInTypes() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("bareWithSubjectTypeAlias.kt")
|
||||||
|
public void testBareWithSubjectTypeAlias() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/types/bareWithSubjectTypeAlias.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/visibility")
|
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/visibility")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -8,13 +8,15 @@ package org.jetbrains.kotlin.fir.resolve
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.FirResolvedReifiedParameterReferenceBuilder
|
import org.jetbrains.kotlin.fir.expressions.builder.FirResolvedReifiedParameterReferenceBuilder
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionWithSmartcast
|
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionWithSmartcast
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedQualifier
|
import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedQualifier
|
||||||
|
import org.jetbrains.kotlin.fir.inferenceContext
|
||||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||||
@@ -28,6 +30,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.bindSymbolToLookupTag
|
|||||||
import org.jetbrains.kotlin.fir.resolve.providers.getSymbolByTypeRef
|
import org.jetbrains.kotlin.fir.resolve.providers.getSymbolByTypeRef
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||||
|
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirDeclaredMemberScopeProvider
|
import org.jetbrains.kotlin.fir.scopes.impl.FirDeclaredMemberScopeProvider
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
|
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
|
||||||
import org.jetbrains.kotlin.fir.symbols.*
|
import org.jetbrains.kotlin.fir.symbols.*
|
||||||
@@ -87,6 +90,15 @@ fun ConeClassLikeType.fullyExpandedType(
|
|||||||
return fullyExpandedTypeNoCache(useSiteSession, expandedConeType)
|
return fullyExpandedTypeNoCache(useSiteSession, expandedConeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ConeKotlinType.fullyExpandedType(
|
||||||
|
useSiteSession: FirSession
|
||||||
|
): ConeKotlinType = when (this) {
|
||||||
|
is ConeFlexibleType ->
|
||||||
|
ConeFlexibleType(lowerBound.fullyExpandedType(useSiteSession), upperBound.fullyExpandedType(useSiteSession))
|
||||||
|
is ConeClassLikeType -> fullyExpandedType(useSiteSession)
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
|
||||||
private fun ConeClassLikeType.fullyExpandedTypeNoCache(
|
private fun ConeClassLikeType.fullyExpandedTypeNoCache(
|
||||||
useSiteSession: FirSession,
|
useSiteSession: FirSession,
|
||||||
expandedConeType: (FirTypeAlias) -> ConeClassLikeType?,
|
expandedConeType: (FirTypeAlias) -> ConeClassLikeType?,
|
||||||
|
|||||||
+3
-2
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
|||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.builder.*
|
import org.jetbrains.kotlin.fir.types.builder.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl
|
|
||||||
import org.jetbrains.kotlin.fir.visitors.*
|
import org.jetbrains.kotlin.fir.visitors.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -379,7 +378,9 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun FirTypeRef.withTypeArgumentsForBareType(argument: FirExpression): FirTypeRef {
|
private fun FirTypeRef.withTypeArgumentsForBareType(argument: FirExpression): FirTypeRef {
|
||||||
val baseTypeArguments = argument.typeRef.coneTypeSafe<ConeKotlinType>()?.typeArguments
|
// TODO: Everything should also work for case of checked-type itself is a type alias
|
||||||
|
val baseTypeArguments =
|
||||||
|
argument.typeRef.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session)?.typeArguments
|
||||||
val type = coneTypeSafe<ConeKotlinType>()
|
val type = coneTypeSafe<ConeKotlinType>()
|
||||||
return if (type?.typeArguments?.isEmpty() != true ||
|
return if (type?.typeArguments?.isEmpty() != true ||
|
||||||
type is ConeTypeParameterType ||
|
type is ConeTypeParameterType ||
|
||||||
|
|||||||
Reference in New Issue
Block a user