[FIR] Resolve where subjects to corresponding type argument
^KTIJ-25295 fixed Merge-request: KT-MR-10044 Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
+12
@@ -1950,6 +1950,18 @@ public class Fe10IdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exte
|
|||||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ internal class KtFirExpressionTypeProvider(
|
|||||||
is FirExpression -> fir.typeRef.coneType.asKtType()
|
is FirExpression -> fir.typeRef.coneType.asKtType()
|
||||||
is FirNamedReference -> fir.getReferencedElementType().asKtType()
|
is FirNamedReference -> fir.getReferencedElementType().asKtType()
|
||||||
is FirStatement -> with(analysisSession) { builtinTypes.UNIT }
|
is FirStatement -> with(analysisSession) { builtinTypes.UNIT }
|
||||||
is FirTypeRef, is FirImport, is FirPackageDirective, is FirLabel -> null
|
is FirTypeRef, is FirImport, is FirPackageDirective, is FirLabel, is FirTypeParameterRef -> null
|
||||||
// For invalid code like the following,
|
// For invalid code like the following,
|
||||||
// ```
|
// ```
|
||||||
// when {
|
// when {
|
||||||
|
|||||||
+8
@@ -218,6 +218,7 @@ internal object FirReferenceResolveHelper {
|
|||||||
is FirResolvable -> getSymbolsByResolvable(fir, expression, session, symbolBuilder)
|
is FirResolvable -> getSymbolsByResolvable(fir, expression, session, symbolBuilder)
|
||||||
is FirNamedArgumentExpression -> getSymbolsByNameArgumentExpression(expression, analysisSession, symbolBuilder)
|
is FirNamedArgumentExpression -> getSymbolsByNameArgumentExpression(expression, analysisSession, symbolBuilder)
|
||||||
is FirEqualityOperatorCall -> getSymbolsByEqualsName(fir, session, analysisSession, symbolBuilder)
|
is FirEqualityOperatorCall -> getSymbolsByEqualsName(fir, session, analysisSession, symbolBuilder)
|
||||||
|
is FirTypeParameter -> getSybmolsByTypeParameter(symbolBuilder, fir)
|
||||||
else -> handleUnknownFirElement(expression, analysisSession, session, symbolBuilder)
|
else -> handleUnknownFirElement(expression, analysisSession, session, symbolBuilder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,6 +431,13 @@ internal object FirReferenceResolveHelper {
|
|||||||
return listOf(symbolBuilder.buildSymbol(fir.symbol))
|
return listOf(symbolBuilder.buildSymbol(fir.symbol))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSybmolsByTypeParameter(
|
||||||
|
symbolBuilder: KtSymbolByFirBuilder,
|
||||||
|
fir: FirTypeParameter
|
||||||
|
): List<KtSymbol> {
|
||||||
|
return listOf(symbolBuilder.buildSymbol(fir.symbol))
|
||||||
|
}
|
||||||
|
|
||||||
private fun getSymbolsByResolvedImport(
|
private fun getSymbolsByResolvedImport(
|
||||||
expression: KtSimpleNameExpression,
|
expression: KtSimpleNameExpression,
|
||||||
builder: KtSymbolByFirBuilder,
|
builder: KtSymbolByFirBuilder,
|
||||||
|
|||||||
+12
@@ -1950,6 +1950,18 @@ public class FirIdeDependentAnalysisSourceModuleReferenceResolveTestGenerated ex
|
|||||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+12
@@ -1834,5 +1834,17 @@ public class FirIdeNormalAnalysisLibrarySourceModuleReferenceResolveTestGenerate
|
|||||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -1950,6 +1950,18 @@ public class FirIdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exten
|
|||||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+12
@@ -1950,6 +1950,18 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceResolveTestGenerate
|
|||||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||||
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/TypeParameterInFunctionLiteral.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/referenceResolve/typeParameter/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun <From, To> copyNotNull(from: List<From>, to: List<To>) where <caret>From : To, To : Any {
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
Resolved to:
|
||||||
|
0: From
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun <From, To> copyNotNull(from: List<From>, to: List<To>) where From : To, <caret>To : Any {
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
Resolved to:
|
||||||
|
0: To
|
||||||
+10
@@ -10,8 +10,10 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.Duplicate
|
|||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.isErrorElement
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.isErrorElement
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.builder.toFirOperationOrNull
|
import org.jetbrains.kotlin.fir.builder.toFirOperationOrNull
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
||||||
|
import org.jetbrains.kotlin.fir.psi
|
||||||
import org.jetbrains.kotlin.fir.references.*
|
import org.jetbrains.kotlin.fir.references.*
|
||||||
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||||
@@ -64,6 +66,14 @@ internal open class FirElementsRecorder : FirVisitor<Unit, MutableMap<KtElement,
|
|||||||
element.acceptChildren(this, data)
|
element.acceptChildren(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visitTypeParameter(typeParameter: FirTypeParameter, data: MutableMap<KtElement, FirElement>) {
|
||||||
|
for (bound in typeParameter.bounds) {
|
||||||
|
val constraintSubject = (bound.psi?.parent as? KtTypeConstraint)?.subjectTypeParameterName ?: continue
|
||||||
|
cache(constraintSubject, typeParameter, data)
|
||||||
|
}
|
||||||
|
super.visitTypeParameter(typeParameter, data)
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitVariableAssignment(variableAssignment: FirVariableAssignment, data: MutableMap<KtElement, FirElement>) {
|
override fun visitVariableAssignment(variableAssignment: FirVariableAssignment, data: MutableMap<KtElement, FirElement>) {
|
||||||
// For the LHS of the assignment, record the assignment itself
|
// For the LHS of the assignment, record the assignment itself
|
||||||
(variableAssignment.lValue.source?.psi as? KtElement)?.let { cache(it, variableAssignment, data) }
|
(variableAssignment.lValue.source?.psi as? KtElement)?.let { cache(it, variableAssignment, data) }
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
fun <From, To> copyNotNull(from: List<From>, to: List<To>) where <expr>From</expr> : To, To : Any {
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
KT element: KtNameReferenceExpression
|
||||||
|
FIR element: FirTypeParameterImpl
|
||||||
|
FIR source kind: KtRealSourceElementKind
|
||||||
|
|
||||||
|
FIR element rendered:
|
||||||
|
[ResolvedTo(BODY_RESOLVE)] From : R|To|
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
fun <From, To> copyNotNull(from: List<From>, to: List<To>) where From : To, <expr>To</expr> : Any {
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
KT element: KtNameReferenceExpression
|
||||||
|
FIR element: FirTypeParameterImpl
|
||||||
|
FIR source kind: KtRealSourceElementKind
|
||||||
|
|
||||||
|
FIR element rendered:
|
||||||
|
[ResolvedTo(BODY_RESOLVE)] To : R|kotlin/Any|
|
||||||
+12
@@ -470,6 +470,18 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
|
|||||||
public void testPropertyDelegateExpression() throws Exception {
|
public void testPropertyDelegateExpression() throws Exception {
|
||||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/propertyDelegateExpression.kt");
|
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/propertyDelegateExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+12
@@ -470,6 +470,18 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
|
|||||||
public void testPropertyDelegateExpression() throws Exception {
|
public void testPropertyDelegateExpression() throws Exception {
|
||||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/propertyDelegateExpression.kt");
|
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/propertyDelegateExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause1.kt")
|
||||||
|
public void testWhereClause1() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/whereClause1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whereClause2.kt")
|
||||||
|
public void testWhereClause2() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/whereClause2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+3
@@ -14,3 +14,6 @@ class SomeList : AbstractList<Int>() {
|
|||||||
|
|
||||||
override fun concat(other: List<Int>): List<Int> = this
|
override fun concat(other: List<Int>): List<Int> = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <From, To> copyNotNull(from: List<From>, to: List<To>) where From : To, To : Any {
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -23,3 +23,4 @@ FILE: typeParameters.kt
|
|||||||
public? open? override fun concat(other: List<Int>): List<Int> { LAZY_BLOCK }
|
public? open? override fun concat(other: List<Int>): List<Int> { LAZY_BLOCK }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public? final? fun <From : To, To : Any> copyNotNull(from: List<From>, to: List<To>): R|kotlin/Unit| { LAZY_BLOCK }
|
||||||
|
|||||||
+2
@@ -27,3 +27,5 @@ FILE: typeParameters.kt
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public? final? fun <From : To, To : Any> copyNotNull(from: List<From>, to: List<To>): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user