FIR: add fake source fir element to it parameter symbol

This commit is contained in:
Ilya Kirillov
2020-12-15 20:26:23 +01:00
parent af0e8b28d5
commit a30d9e0ed3
4 changed files with 9 additions and 3 deletions
@@ -5,12 +5,14 @@
package org.jetbrains.kotlin.fir.resolve.inference package org.jetbrains.kotlin.fir.resolve.inference
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirResolvable import org.jetbrains.kotlin.fir.expressions.FirResolvable
import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.fakeElement
import org.jetbrains.kotlin.fir.resolve.ResolutionMode import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.Candidate
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
@@ -33,7 +35,6 @@ import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
import org.jetbrains.kotlin.types.model.StubTypeMarker import org.jetbrains.kotlin.types.model.StubTypeMarker
@@ -183,6 +184,7 @@ class FirCallCompleter(
val name = Name.identifier("it") val name = Name.identifier("it")
val itType = parameters.single() val itType = parameters.single()
buildValueParameter { buildValueParameter {
source = lambdaAtom.atom.source?.fakeElement(FirFakeSourceElementKind.ItLambdaParameter)
session = this@FirCallCompleter.session session = this@FirCallCompleter.session
origin = FirDeclarationOrigin.Source origin = FirDeclarationOrigin.Source
returnTypeRef = buildResolvedTypeRef { type = itType.approximateLambdaInputType() } returnTypeRef = buildResolvedTypeRef { type = itType.approximateLambdaInputType() }
@@ -157,6 +157,10 @@ sealed class FirFakeSourceElementKind : FirSourceElementKind() {
// Part of desugared x?.y // Part of desugared x?.y
object CheckedSafeCallSubject : FirFakeSourceElementKind() object CheckedSafeCallSubject : FirFakeSourceElementKind()
// { it + 1} --> { it -> it + 1 }
// where `it` parameter declaration has fake source
object ItLambdaParameter : FirFakeSourceElementKind()
} }
sealed class FirSourceElement { sealed class FirSourceElement {
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.fir.low.level.api.api
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.unwrapFakeOverrides import org.jetbrains.kotlin.fir.unwrapFakeOverrides
import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo import org.jetbrains.kotlin.idea.caches.project.IdeaModuleInfo
@@ -109,7 +110,7 @@ fun <D : FirDeclaration, R> D.withFirDeclaration(
-> { -> {
val cache = session.cache val cache = session.cache
val file = resolveState.getFirFile(this, cache) val file = resolveState.getFirFile(this, cache)
?: error("Fir file was not found for\n${render()}\n${ktDeclaration.getElementTextInContext()}") ?: error("Fir file was not found for\n${render()}\n${(psi as? KtElement)?.getElementTextInContext()}")
cache.firFileLockProvider.withReadLock(file) { action(this) } cache.firFileLockProvider.withReadLock(file) { action(this) }
} }
else -> action(this) else -> action(this)
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_FIR
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">test</info>() { fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">test</info>() {
val <info textAttributesKey="KOTLIN_LOCAL_VARIABLE">vect</info> = <info textAttributesKey="KOTLIN_CONSTRUCTOR">MyIterable</info><<info textAttributesKey="KOTLIN_CLASS">Int</info>>() val <info textAttributesKey="KOTLIN_LOCAL_VARIABLE">vect</info> = <info textAttributesKey="KOTLIN_CONSTRUCTOR">MyIterable</info><<info textAttributesKey="KOTLIN_CLASS">Int</info>>()
<info textAttributesKey="KOTLIN_LOCAL_VARIABLE">vect</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">filter</info> { <info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info> != 2 }.<info textAttributesKey="KOTLIN_FUNCTION_CALL">forEach</info> { <info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">toString</info>() } <info textAttributesKey="KOTLIN_LOCAL_VARIABLE">vect</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">filter</info> { <info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info> != 2 }.<info textAttributesKey="KOTLIN_FUNCTION_CALL">forEach</info> { <info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">toString</info>() }