FIR: Fix exception in inference
Default SimpleTypeMarker::withNullability from ConeTypeContext doesn't take into account inference-related type kinds like type variables These cases are properly handled in org.jetbrains.kotlin.fir.resolve.ResolveUtilsKt#withNullability Original exception trace: at org.jetbrains.kotlin.fir.types.ConeTypeContext$DefaultImpls.withNullability(ConeTypeContext.kt:142) at org.jetbrains.kotlin.fir.resolve.calls.ConeInferenceContext$DefaultImpls.withNullability(ConeInferenceContext.kt) at org.jetbrains.kotlin.fir.resolve.transformers.FirBodyResolveTransformerKt$inferenceComponents$1.withNullability(FirBodyResolveTransformer.kt:943) at org.jetbrains.kotlin.fir.resolve.calls.ConeInferenceContext$DefaultImpls.makeSimpleTypeDefinitelyNotNullOrNotNull(ConeInferenceContext.kt:195) at org.jetbrains.kotlin.fir.resolve.transformers.FirBodyResolveTransformerKt$inferenceComponents$1.makeSimpleTypeDefinitelyNotNullOrNotNull(FirBodyResolveTransformer.kt:943) at org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl.makeSimpleTypeDefinitelyNotNullOrNotNull(NewConstraintSystemImpl.kt) at org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector$TypeCheckerContext.makeSimpleTypeDefinitelyNotNullOrNotNull(ConstraintInjector.kt) at org.jetbrains.kotlin.resolve.calls.inference.components.AbstractTypeCheckerContextForConstraintSystem.simplifyLowerConstraint(AbstractTypeCheckerContextForConstraintSystem.kt:163) at org.jetbrains.kotlin.resolve.calls.inference.components.AbstractTypeCheckerContextForConstraintSystem.internalAddSubtypeConstraint(AbstractTypeCheckerContextForConstraintSystem.kt:71) at org.jetbrains.kotlin.resolve.calls.inference.components.AbstractTypeCheckerContextForConstraintSystem.addSubtypeConstraint(AbstractTypeCheckerContextForConstraintSystem.kt:50) at org.jetbrains.kotlin.types.AbstractTypeChecker.completeIsSubTypeOf(AbstractTypeChecker.kt:193) at org.jetbrains.kotlin.types.AbstractTypeChecker.isSubtypeOf(AbstractTypeChecker.kt:164) at org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector$TypeCheckerContext.runIsSubtypeOf(ConstraintInjector.kt:153) at org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector.addSubTypeConstraintAndIncorporateIt(ConstraintInjector.kt:77) at org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector.addInitialSubtypeConstraint(ConstraintInjector.kt:55) at org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl.addSubtypeConstraint(NewConstraintSystemImpl.kt:84) at org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderKt$addSubtypeConstraintIfCompatible$1.invoke(ConstraintSystemBuilder.kt:61) at org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderKt$addSubtypeConstraintIfCompatible$1.invoke(ConstraintSystemBuilder.kt) at org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl.runTransaction(NewConstraintSystemImpl.kt:130) at org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderKt.addSubtypeConstraintIfCompatible(ConstraintSystemBuilder.kt:60) at org.jetbrains.kotlin.fir.resolve.calls.ArgumentsKt.checkApplicabilityForArgumentType(Arguments.kt:170) at org.jetbrains.kotlin.fir.resolve.calls.ArgumentsKt.resolvePlainArgumentType(Arguments.kt:158) at org.jetbrains.kotlin.fir.resolve.calls.ArgumentsKt.resolveSubCallArgument(Arguments.kt:123) at org.jetbrains.kotlin.fir.resolve.calls.ArgumentsKt.resolveArgumentExpression(Arguments.kt:42) at org.jetbrains.kotlin.fir.resolve.calls.ArgumentsKt.resolveArgument(Arguments.kt:196) at org.jetbrains.kotlin.fir.resolve.calls.CheckArguments.check(ResolverParts.kt:145) at org.jetbrains.kotlin.fir.resolve.calls.CheckArguments$check$1.invokeSuspend(ResolverParts.kt)
This commit is contained in:
@@ -127,20 +127,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
|
||||
override fun SimpleTypeMarker.withNullability(nullable: Boolean): SimpleTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
if (nullability.isNullable == nullable) return this
|
||||
return when (this) {
|
||||
is ConeCapturedType -> ConeCapturedType(captureStatus, lowerType, ConeNullability.create(nullable), constructor)
|
||||
is ConeTypeParameterType -> ConeTypeParameterTypeImpl(lookupTag, nullable)
|
||||
is ConeClassErrorType -> this
|
||||
is ConeClassType -> ConeClassTypeImpl(lookupTag, typeArguments, nullable)
|
||||
is ConeAbbreviatedType -> ConeAbbreviatedTypeImpl(
|
||||
lookupTag,
|
||||
typeArguments,
|
||||
nullable
|
||||
)
|
||||
is ConeIntersectionType -> this.withNullability(ConeNullability.create(nullable))
|
||||
else -> error("!")
|
||||
}
|
||||
return withNullability(ConeNullability.create(nullable))
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// FILE: BindingContext.java
|
||||
public interface BindingContext {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
<K, V> V get(ReadOnlySlice<K, V> slice, K key);
|
||||
}
|
||||
|
||||
// FILE: ReadOnlySlice.java
|
||||
public interface ReadOnlySlice<K, V> {}
|
||||
|
||||
// FILE: Slices.java
|
||||
|
||||
public class Slices {
|
||||
public static ReadOnlySlice<String, Double> X = null;
|
||||
public static ReadOnlySlice<Integer, String> Y = null;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun bar(bindingContext: BindingContext) {
|
||||
bindingContext[Slices.X, bindingContext[Slices.Y, 1]]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
FILE: main.kt
|
||||
public final fun bar(bindingContext: R|BindingContext|): R|kotlin/Unit| {
|
||||
R|<local>/bindingContext|.R|/BindingContext.get|<R|ft<kotlin/String, kotlin/String?>!|, R|ft<kotlin/Double, kotlin/Double?>!|>(Q|Slices|.R|/Slices.X|, R|<local>/bindingContext|.R|/BindingContext.get|<R|ft<kotlin/Int, kotlin/Int?>!|, R|ft<kotlin/String, kotlin/String?>!|>(Q|Slices|.R|/Slices.Y|, Int(1)))
|
||||
}
|
||||
+5
@@ -41,6 +41,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/diagnostics/j+k"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("complexFlexibleInference.kt")
|
||||
public void testComplexFlexibleInference() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("KJKComplexHierarchy.kt")
|
||||
public void testKJKComplexHierarchy() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/diagnostics/j+k/KJKComplexHierarchy.kt");
|
||||
|
||||
Reference in New Issue
Block a user