[FIR] Replace uninferred type variables and stub types during delegate inference
This commit is contained in:
committed by
Space Team
parent
94387da867
commit
22c21ca4df
+36
-3
@@ -6,6 +6,8 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.substitution
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.withCombinedAttributesFrom
|
||||
@@ -19,6 +21,7 @@ import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
import org.jetbrains.kotlin.types.model.typeConstructor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
|
||||
abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContext) : ConeSubstitutor() {
|
||||
protected fun wrapProjection(old: ConeTypeProjection, newType: ConeKotlinType): ConeTypeProjection {
|
||||
@@ -285,12 +288,12 @@ fun createTypeSubstitutorByTypeConstructor(
|
||||
|
||||
internal class ConeTypeSubstitutorByTypeConstructor(
|
||||
private val map: Map<TypeConstructorMarker, ConeKotlinType>,
|
||||
private val context: ConeTypeContext,
|
||||
typeContext: ConeTypeContext,
|
||||
private val approximateIntegerLiterals: Boolean
|
||||
) : AbstractConeSubstitutor(context), TypeSubstitutorMarker {
|
||||
) : AbstractConeSubstitutor(typeContext), TypeSubstitutorMarker {
|
||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||
if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null
|
||||
val new = map[type.typeConstructor(context)] ?: return null
|
||||
val new = map[type.typeConstructor(typeContext)] ?: return null
|
||||
val approximatedIntegerLiteralType = if (approximateIntegerLiterals) new.approximateIntegerLiteralType() else new
|
||||
return approximatedIntegerLiteralType.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
|
||||
}
|
||||
@@ -308,3 +311,33 @@ class NotFixedTypeToVariableSubstitutorForDelegateInference(
|
||||
}
|
||||
}
|
||||
|
||||
class ConeStubAndTypeVariableToErrorTypeSubstitutor(
|
||||
typeContext: ConeTypeContext,
|
||||
private val stubTypesToReplace: Collection<ConeStubTypeConstructor>
|
||||
) : AbstractConeSubstitutor(typeContext) {
|
||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||
return when (type) {
|
||||
is ConeTypeVariableType -> ConeErrorType(
|
||||
ConeSimpleDiagnostic("Type for ${type.lookupTag.debugName} is not inferred", DiagnosticKind.InferenceError),
|
||||
isUninferredParameter = true
|
||||
)
|
||||
is ConeStubType -> runIf(type.constructor in stubTypesToReplace) {
|
||||
ConeErrorType(
|
||||
ConeSimpleDiagnostic(
|
||||
"Type for stub of ${type.constructor.variable.typeConstructor.debugName} is not inferred",
|
||||
DiagnosticKind.InferenceError
|
||||
),
|
||||
isUninferredParameter = true
|
||||
)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ConeSubstitutor.replaceStubsAndTypeVariablesToErrors(
|
||||
typeContext: ConeTypeContext,
|
||||
stubTypesToReplace: Collection<ConeStubTypeConstructor>
|
||||
): ConeSubstitutor {
|
||||
return ChainedSubstitutor(this, ConeStubAndTypeVariableToErrorTypeSubstitutor(typeContext, stubTypesToReplace))
|
||||
}
|
||||
|
||||
+4
-4
@@ -10,9 +10,7 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvable
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeFixVariableConstraintPosition
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ChainedSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.NotFixedTypeToVariableSubstitutorForDelegateInference
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
@@ -228,9 +226,11 @@ class FirDelegatedPropertyInferenceSession(
|
||||
fun createFinalSubstitutor(): ConeSubstitutor {
|
||||
val stubTypeSubstitutor = createNonFixedTypeToVariableSubstitutor()
|
||||
|
||||
val typeContext = components.session.typeContext
|
||||
val resultSubstitutor = resultingConstraintSystem.asReadOnlyStorage()
|
||||
.buildAbstractResultingSubstitutor(components.session.typeContext) as ConeSubstitutor
|
||||
.buildAbstractResultingSubstitutor(typeContext) as ConeSubstitutor
|
||||
return ChainedSubstitutor(stubTypeSubstitutor, resultSubstitutor)
|
||||
.replaceStubsAndTypeVariablesToErrors(typeContext, stubTypesByTypeVariable.values.map { it.constructor })
|
||||
}
|
||||
|
||||
val stubTypesByTypeVariable: MutableMap<ConeTypeVariable, ConeStubType> = mutableMapOf()
|
||||
|
||||
-2
@@ -265,7 +265,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
}
|
||||
|
||||
private fun transformPropertyAccessorsWithDelegate(property: FirProperty) {
|
||||
|
||||
context.forPropertyDelegateAccessors(property, resolutionContext, callCompleter) {
|
||||
// Resolve delegate expression, after that, delegate will contain either expr.provideDelegate or expr
|
||||
if (property.isLocal) {
|
||||
@@ -282,7 +281,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
|
||||
val finalSubstitutor = createFinalSubstitutor()
|
||||
|
||||
// Replace stub types with corresponding type variable types
|
||||
val stubTypeCompletionResultsWriter = FirStubTypeTransformer(finalSubstitutor)
|
||||
property.transformSingle(stubTypeCompletionResultsWriter, null)
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
// FILE: test.kt
|
||||
val bar2 by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, NO_VALUE_FOR_PARAMETER!>bar2()<!>
|
||||
val bar2 by <!NO_VALUE_FOR_PARAMETER!>bar2()<!>
|
||||
|
||||
// FILE: lt/neworld/compiler/Foo.kt
|
||||
package lt.neworld.compiler
|
||||
|
||||
class Foo {
|
||||
val bar by <!DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, NO_VALUE_FOR_PARAMETER!>bar()<!>
|
||||
val bar by <!NO_VALUE_FOR_PARAMETER!>bar()<!>
|
||||
}
|
||||
|
||||
// FILE: lt/neworld/compiler/bar/Bar.kt
|
||||
|
||||
@@ -8,7 +8,7 @@ inline fun <reified Self : DatabaseEntity, reified Target : DatabaseEntity> Self
|
||||
property: KProperty1<Target, MutableCollection<Self>>): Delegate<Self, Target?> = TODO()
|
||||
|
||||
class GitLabBuildProcessor: DatabaseEntity {
|
||||
var processor by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>parent<!>(GitLabChangesProcessor::buildProcessors)
|
||||
var processor by parent(GitLabChangesProcessor::buildProcessors)
|
||||
}
|
||||
|
||||
interface DatabaseEntity: Entity
|
||||
|
||||
@@ -9,7 +9,7 @@ inline fun <reified Self : DatabaseEntity, reified Target : DatabaseEntity> Self
|
||||
property: KProperty1<Target, MutableCollection<Self>>): Delegate<Self, Target?> = TODO()
|
||||
|
||||
class GitLabBuildProcessor: DatabaseEntity {
|
||||
var processor by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>parent<!>(GitLabChangesProcessor::buildProcessors)
|
||||
var processor by parent(GitLabChangesProcessor::buildProcessors)
|
||||
}
|
||||
|
||||
interface DatabaseEntity: Entity
|
||||
|
||||
+1
-1
@@ -69,4 +69,4 @@ fun test6() {
|
||||
genericLambda { it.extension() }
|
||||
use(::extension)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -70,4 +70,4 @@ fun test6() {
|
||||
genericLambda { it.extension() }
|
||||
use(::extension)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
// FIR_DUMP
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class ProcessorWithParent : Entity {
|
||||
var processor by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>parent<!>(ProcessorWithChildren::processors)
|
||||
var processor by parent(ProcessorWithChildren::processors)
|
||||
}
|
||||
|
||||
class ProcessorWithChildren : Entity {
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
FILE: kt50994.fir.kt
|
||||
public final class ProcessorWithParent : R|Entity| {
|
||||
public constructor(): R|ProcessorWithParent| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final var processor: R|ProcessorWithChildren?|by this@R|/ProcessorWithParent|.R|/parent|<R|ProcessorWithParent|, R|ProcessorWithChildren|>(Q|ProcessorWithChildren|::R|/ProcessorWithChildren.processors|)
|
||||
public get(): R|ProcessorWithChildren?| {
|
||||
^ this@R|/ProcessorWithParent|.D|/ProcessorWithParent.processor|.R|SubstitutionOverride</Delegate.getValue: R|Stub (chain inference): TypeVariable(_TP)?|>|(this@R|/ProcessorWithParent|, ::R|/ProcessorWithParent.processor|)
|
||||
}
|
||||
public set(<set-?>: R|ProcessorWithChildren?|): R|kotlin/Unit| {
|
||||
this@R|/ProcessorWithParent|.D|/ProcessorWithParent.processor|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/ProcessorWithParent|, ::R|/ProcessorWithParent.processor|, R|<local>/processor|)
|
||||
}
|
||||
|
||||
}
|
||||
public final class ProcessorWithChildren : R|Entity| {
|
||||
public constructor(): R|ProcessorWithChildren| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final var processors: R|kotlin/collections/MutableCollection<ERROR CLASS: Type for TC is not inferred>|by this@R|/ProcessorWithChildren|.<Inapplicable(INAPPLICABLE): /children>#<R|ERROR CLASS: Type for SC is not inferred|, R|ERROR CLASS: Type for TC is not inferred|>(<getClass>(Q|ProcessorWithParent|).R|kotlin/jvm/java|<R|ProcessorWithParent|>, Q|ProcessorWithParent|::<Unresolved reference: processor>#)
|
||||
public get(): R|kotlin/collections/MutableCollection<ERROR CLASS: Type for TC is not inferred>| {
|
||||
^ this@R|/ProcessorWithChildren|.D|/ProcessorWithChildren.processors|.R|SubstitutionOverride</Delegate.getValue: R|kotlin/collections/MutableCollection<Stub (chain inference): TypeVariable(_TC)>|>|(this@R|/ProcessorWithChildren|, ::R|/ProcessorWithChildren.processors|)
|
||||
}
|
||||
public set(<set-?>: R|kotlin/collections/MutableCollection<ERROR CLASS: Type for TC is not inferred>|): R|kotlin/Unit| {
|
||||
this@R|/ProcessorWithChildren|.D|/ProcessorWithChildren.processors|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/ProcessorWithChildren|, ::R|/ProcessorWithChildren.processors|, R|<local>/processors|)
|
||||
}
|
||||
|
||||
}
|
||||
public final class Processor2WithParent : R|Entity| {
|
||||
public constructor(): R|Processor2WithParent| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final var processor: R|Processor2WithChildren?|by this@R|/Processor2WithParent|.R|/parent|<R|Processor2WithParent|, R|Processor2WithChildren|>(Q|Processor2WithChildren|::R|/Processor2WithChildren.processors|)
|
||||
public get(): R|Processor2WithChildren?| {
|
||||
^ this@R|/Processor2WithParent|.D|/Processor2WithParent.processor|.R|SubstitutionOverride</Delegate.getValue: R|Processor2WithChildren?|>|(this@R|/Processor2WithParent|, ::R|/Processor2WithParent.processor|)
|
||||
}
|
||||
public set(<set-?>: R|Processor2WithChildren?|): R|kotlin/Unit| {
|
||||
this@R|/Processor2WithParent|.D|/Processor2WithParent.processor|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/Processor2WithParent|, ::R|/Processor2WithParent.processor|, R|<local>/processor|)
|
||||
}
|
||||
|
||||
}
|
||||
public final class Processor2WithChildren : R|Entity| {
|
||||
public constructor(): R|Processor2WithChildren| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final var processors: R|kotlin/collections/MutableCollection<Processor2WithParent>|by this@R|/Processor2WithChildren|.R|/children|<R|Processor2WithChildren|, R|Processor2WithParent|>(<getClass>(Q|Processor2WithParent|).R|kotlin/jvm/java|<R|Processor2WithParent|>, Q|Processor2WithParent|::R|/Processor2WithParent.processor|)
|
||||
public get(): R|kotlin/collections/MutableCollection<Processor2WithParent>| {
|
||||
^ this@R|/Processor2WithChildren|.D|/Processor2WithChildren.processors|.R|SubstitutionOverride</Delegate.getValue: R|kotlin/collections/MutableCollection<Stub (chain inference): TypeVariable(_TC)>|>|(this@R|/Processor2WithChildren|, ::R|/Processor2WithChildren.processors|)
|
||||
}
|
||||
public set(<set-?>: R|kotlin/collections/MutableCollection<Processor2WithParent>|): R|kotlin/Unit| {
|
||||
this@R|/Processor2WithChildren|.D|/Processor2WithChildren.processors|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/Processor2WithChildren|, ::R|/Processor2WithChildren.processors|, R|<local>/processors|)
|
||||
}
|
||||
|
||||
}
|
||||
public final class Processor3WithParent : R|Entity| {
|
||||
public constructor(): R|Processor3WithParent| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final var processor: R|Processor3WithChildren?|by this@R|/Processor3WithParent|.R|/parent|<R|Processor3WithParent|, R|Processor3WithChildren|>(Q|Processor3WithChildren|::R|/Processor3WithChildren.processors|)
|
||||
public get(): R|Processor3WithChildren?| {
|
||||
^ this@R|/Processor3WithParent|.D|/Processor3WithParent.processor|.R|SubstitutionOverride</Delegate.getValue: R|Processor3WithChildren?|>|(this@R|/Processor3WithParent|, ::R|/Processor3WithParent.processor|)
|
||||
}
|
||||
public set(<set-?>: R|Processor3WithChildren?|): R|kotlin/Unit| {
|
||||
this@R|/Processor3WithParent|.D|/Processor3WithParent.processor|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/Processor3WithParent|, ::R|/Processor3WithParent.processor|, R|<local>/processor|)
|
||||
}
|
||||
|
||||
}
|
||||
public final class Processor3WithChildren : R|Entity| {
|
||||
public constructor(): R|Processor3WithChildren| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final var processors: R|kotlin/collections/MutableCollection<Processor3WithParent>|by this@R|/Processor3WithChildren|.R|/children|<R|Processor3WithChildren|, R|Processor3WithParent|>(<getClass>(Q|Processor3WithParent|).R|kotlin/jvm/java|<R|Processor3WithParent|>, Q|Processor3WithParent|::R|/Processor3WithParent.processor|)
|
||||
public get(): R|kotlin/collections/MutableCollection<Processor3WithParent>| {
|
||||
^ this@R|/Processor3WithChildren|.D|/Processor3WithChildren.processors|.R|SubstitutionOverride</Delegate.getValue: R|kotlin/collections/MutableCollection<Stub (chain inference): TypeVariable(_TC)>|>|(this@R|/Processor3WithChildren|, ::R|/Processor3WithChildren.processors|)
|
||||
}
|
||||
public set(<set-?>: R|kotlin/collections/MutableCollection<Processor3WithParent>|): R|kotlin/Unit| {
|
||||
this@R|/Processor3WithChildren|.D|/Processor3WithChildren.processors|.R|SubstitutionOverride</Delegate.setValue: R|kotlin/Unit|>|(this@R|/Processor3WithChildren|, ::R|/Processor3WithChildren.processors|, R|<local>/processors|)
|
||||
}
|
||||
|
||||
}
|
||||
public final inline fun <reified SP : R|Entity|, reified TP : R|Entity|> R|SP|.parent(property: R|kotlin/reflect/KProperty1<TP, kotlin/collections/MutableCollection<SP>>|): R|Delegate<SP, TP?>| {
|
||||
^parent Null(null)!!
|
||||
}
|
||||
public final fun <SC : R|Entity|, TC : R|Entity|> R|SC|.children(clazz: R|java/lang/Class<TC>|, property: R|kotlin/reflect/KProperty1<TC, SC?>|, name: R|kotlin/String| = R|<local>/property|.R|SubstitutionOverride<kotlin/reflect/KProperty1.name: R|kotlin/String|>|): R|Delegate<SC, kotlin/collections/MutableCollection<TC>>| {
|
||||
^children Null(null)!!
|
||||
}
|
||||
public abstract interface Delegate<R : R|Entity|, T> : R|kotlin/properties/ReadWriteProperty<R, T>| {
|
||||
}
|
||||
public abstract interface Entity : R|kotlin/Any| {
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_DUMP
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
|
||||
Reference in New Issue
Block a user