[FIR] Report errors for upper bounded type variables by an empty intersection type
^KT-51221 Fixed
This commit is contained in:
committed by
teamcity
parent
65213e9a42
commit
c16ae81a48
+24
@@ -13834,6 +13834,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt45461.kt")
|
||||||
|
public void testKt45461() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt46515.kt")
|
@TestMetadata("kt46515.kt")
|
||||||
public void testKt46515() throws Exception {
|
public void testKt46515() throws Exception {
|
||||||
@@ -13846,6 +13852,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48765.kt")
|
||||||
|
public void testKt48765() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt48765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48935.kt")
|
||||||
|
public void testKt48935() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt49658.kt")
|
@TestMetadata("kt49658.kt")
|
||||||
public void testKt49658() throws Exception {
|
public void testKt49658() throws Exception {
|
||||||
@@ -13858,6 +13876,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49661.kt")
|
||||||
|
public void testKt49661() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt49661.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt6175.kt")
|
@TestMetadata("kt6175.kt")
|
||||||
public void testKt6175() throws Exception {
|
public void testKt6175() throws Exception {
|
||||||
|
|||||||
+24
@@ -13834,6 +13834,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt45461.kt")
|
||||||
|
public void testKt45461() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt46515.kt")
|
@TestMetadata("kt46515.kt")
|
||||||
public void testKt46515() throws Exception {
|
public void testKt46515() throws Exception {
|
||||||
@@ -13846,6 +13852,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48765.kt")
|
||||||
|
public void testKt48765() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt48765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48935.kt")
|
||||||
|
public void testKt48935() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt49658.kt")
|
@TestMetadata("kt49658.kt")
|
||||||
public void testKt49658() throws Exception {
|
public void testKt49658() throws Exception {
|
||||||
@@ -13858,6 +13876,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49661.kt")
|
||||||
|
public void testKt49661() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt49661.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt6175.kt")
|
@TestMetadata("kt6175.kt")
|
||||||
public void testKt6175() throws Exception {
|
public void testKt6175() throws Exception {
|
||||||
|
|||||||
+24
@@ -13834,6 +13834,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt40396.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt45461.kt")
|
||||||
|
public void testKt45461() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt45461.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt46515.kt")
|
@TestMetadata("kt46515.kt")
|
||||||
public void testKt46515() throws Exception {
|
public void testKt46515() throws Exception {
|
||||||
@@ -13846,6 +13852,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48765.kt")
|
||||||
|
public void testKt48765() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt48765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt48935.kt")
|
||||||
|
public void testKt48935() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt48935.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt49658.kt")
|
@TestMetadata("kt49658.kt")
|
||||||
public void testKt49658() throws Exception {
|
public void testKt49658() throws Exception {
|
||||||
@@ -13858,6 +13876,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49661.kt")
|
||||||
|
public void testKt49661() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt49661.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt6175.kt")
|
@TestMetadata("kt6175.kt")
|
||||||
public void testKt6175() throws Exception {
|
public void testKt6175() throws Exception {
|
||||||
|
|||||||
+6
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
|
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||||
|
import org.jetbrains.kotlin.diagnostics.deprecationError2
|
||||||
import org.jetbrains.kotlin.fir.FirModuleData
|
import org.jetbrains.kotlin.fir.FirModuleData
|
||||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||||
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.*
|
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.*
|
||||||
@@ -683,6 +684,11 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
|||||||
val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning<PsiElement>(PositioningStrategy.REFERENCED_NAME_BY_QUALIFIED) {
|
val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning<PsiElement>(PositioningStrategy.REFERENCED_NAME_BY_QUALIFIED) {
|
||||||
parameter<FqName>("kotlinClass")
|
parameter<FqName>("kotlinClass")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by error<PsiElement> {
|
||||||
|
parameter<String>("typeVariableDescription")
|
||||||
|
parameter<Collection<ConeKotlinType>>("incompatibleTypes")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val REFLECTION by object : DiagnosticGroup("Reflection") {
|
val REFLECTION by object : DiagnosticGroup("Reflection") {
|
||||||
|
|||||||
@@ -412,6 +412,7 @@ object FirErrors {
|
|||||||
val SMARTCAST_IMPOSSIBLE by error4<KtExpression, ConeKotlinType, FirExpression, String, Boolean>()
|
val SMARTCAST_IMPOSSIBLE by error4<KtExpression, ConeKotlinType, FirExpression, String, Boolean>()
|
||||||
val REDUNDANT_NULLABLE by warning0<KtTypeReference>(SourceElementPositioningStrategies.REDUNDANT_NULLABLE)
|
val REDUNDANT_NULLABLE by warning0<KtTypeReference>(SourceElementPositioningStrategies.REDUNDANT_NULLABLE)
|
||||||
val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning1<PsiElement, FqName>(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED)
|
val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning1<PsiElement, FqName>(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED)
|
||||||
|
val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by error2<PsiElement, String, Collection<ConeKotlinType>>()
|
||||||
|
|
||||||
// Reflection
|
// Reflection
|
||||||
val EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED by error1<KtExpression, FirCallableSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
val EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED by error1<KtExpression, FirCallableSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||||
|
|||||||
+7
@@ -253,6 +253,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INCORRECT_CHARACT
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INC_DEC_SHOULD_NOT_RETURN_UNIT
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INC_DEC_SHOULD_NOT_RETURN_UNIT
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFERENCE_ERROR
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFERENCE_ERROR
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFERENCE_UNSUCCESSFUL_FORK
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFERENCE_UNSUCCESSFUL_FORK
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFIX_MODIFIER_REQUIRED
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFIX_MODIFIER_REQUIRED
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INITIALIZATION_BEFORE_DECLARATION
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INITIALIZATION_BEFORE_DECLARATION
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION
|
||||||
@@ -946,6 +947,12 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
|||||||
map.put(REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION, "Redundant spread (*) operator")
|
map.put(REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_ANNOTATION, "Redundant spread (*) operator")
|
||||||
map.put(REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION, "Redundant spread (*) operator")
|
map.put(REDUNDANT_SPREAD_OPERATOR_IN_NAMED_FORM_IN_FUNCTION, "Redundant spread (*) operator")
|
||||||
map.put(INFERENCE_UNSUCCESSFUL_FORK, "Unsuccessful inference fork at position: {0}", TO_STRING)
|
map.put(INFERENCE_UNSUCCESSFUL_FORK, "Unsuccessful inference fork at position: {0}", TO_STRING)
|
||||||
|
map.put(
|
||||||
|
INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION,
|
||||||
|
"Type argument for a type parameter {0} can''t be inferred because it''s upper bounded by incompatible types: {1}",
|
||||||
|
TO_STRING,
|
||||||
|
RENDER_COLLECTION_OF_TYPES
|
||||||
|
)
|
||||||
|
|
||||||
map.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", TO_STRING, TO_STRING, NOT_RENDERED)
|
map.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", TO_STRING, TO_STRING, NOT_RENDERED)
|
||||||
map.put(THROWABLE_TYPE_MISMATCH, "Throwable type mismatch: actual type is {0}", TO_STRING, NOT_RENDERED)
|
map.put(THROWABLE_TYPE_MISMATCH, "Throwable type mismatch: actual type is {0}", TO_STRING, NOT_RENDERED)
|
||||||
|
|||||||
+23
@@ -17,12 +17,14 @@ import org.jetbrains.kotlin.fir.declarations.utils.isInfix
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
|
import org.jetbrains.kotlin.fir.declarations.utils.isOperator
|
||||||
import org.jetbrains.kotlin.fir.diagnostics.*
|
import org.jetbrains.kotlin.fir.diagnostics.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.*
|
import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.calls.InferredEmptyIntersectionDiagnostic
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeVariableForLambdaReturnType
|
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeVariableForLambdaReturnType
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition
|
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExpectedTypeConstraintPosition
|
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExpectedTypeConstraintPosition
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition
|
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
@@ -253,6 +255,8 @@ private fun mapInapplicableCandidateError(
|
|||||||
diagnostic.candidate
|
diagnostic.candidate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
is InferredEmptyIntersectionDiagnostic ->
|
||||||
|
reportInferredIntoEmptyIntersectionError(source, rootCause.typeVariable, rootCause.incompatibleTypes)
|
||||||
else -> genericDiagnostic
|
else -> genericDiagnostic
|
||||||
}
|
}
|
||||||
}.distinct()
|
}.distinct()
|
||||||
@@ -388,10 +392,29 @@ private fun ConstraintSystemError.toDiagnostic(
|
|||||||
position.initialConstraint.asStringWithoutPosition(),
|
position.initialConstraint.asStringWithoutPosition(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
is InferredEmptyIntersection -> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
reportInferredIntoEmptyIntersectionError(
|
||||||
|
source,
|
||||||
|
typeVariable as ConeTypeVariable,
|
||||||
|
incompatibleTypes as Collection<ConeKotlinType>
|
||||||
|
)
|
||||||
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun reportInferredIntoEmptyIntersectionError(
|
||||||
|
source: KtSourceElement,
|
||||||
|
typeVariable: ConeTypeVariable,
|
||||||
|
incompatibleTypes: Collection<ConeKotlinType>,
|
||||||
|
): KtDiagnosticWithParameters2<String, Collection<ConeKotlinType>>? {
|
||||||
|
val typeVariableText =
|
||||||
|
(typeVariable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag)?.name?.asString()
|
||||||
|
?: typeVariable.toString()
|
||||||
|
return FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION.createOn(source, typeVariableText, incompatibleTypes)
|
||||||
|
}
|
||||||
|
|
||||||
private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType
|
private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType
|
||||||
private val NewConstraintError.upperConeType: ConeKotlinType get() = upperType as ConeKotlinType
|
private val NewConstraintError.upperConeType: ConeKotlinType get() = upperType as ConeKotlinType
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
|||||||
import org.jetbrains.kotlin.fir.resolve.calls.FirErrorReferenceWithCandidate
|
import org.jetbrains.kotlin.fir.resolve.calls.FirErrorReferenceWithCandidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer
|
import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeConstraintSystemHasContradiction
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConePropertyAsOperator
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeTypeParameterInQualifiedAccess
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom
|
import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
@@ -54,6 +51,7 @@ import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
|||||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.model.InferredEmptyIntersection
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||||
@@ -856,6 +854,9 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
return varargArgumentsExpression
|
return varargArgumentsExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FirNamedReferenceWithCandidate.hasAdditionalResolutionErrors(): Boolean =
|
||||||
|
candidate.system.errors.any { it is InferredEmptyIntersection }
|
||||||
|
|
||||||
private fun FirNamedReferenceWithCandidate.toResolvedReference(): FirNamedReference {
|
private fun FirNamedReferenceWithCandidate.toResolvedReference(): FirNamedReference {
|
||||||
val errorDiagnostic = when {
|
val errorDiagnostic = when {
|
||||||
this is FirErrorReferenceWithCandidate -> this.diagnostic
|
this is FirErrorReferenceWithCandidate -> this.diagnostic
|
||||||
@@ -867,6 +868,9 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
|
|
||||||
ConeConstraintSystemHasContradiction(candidate)
|
ConeConstraintSystemHasContradiction(candidate)
|
||||||
}
|
}
|
||||||
|
// NB: these additional errors might not lead to marking candidate unsuccessful because it may be a warning in FE 1.0
|
||||||
|
// We consider those warnings as errors in FIR
|
||||||
|
hasAdditionalResolutionErrors() -> ConeConstraintSystemHasContradiction(candidate)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression
|
|||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
|
import org.jetbrains.kotlin.fir.types.ConeTypeVariable
|
||||||
import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget
|
import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||||
@@ -27,6 +28,11 @@ abstract class InapplicableArgumentDiagnostic : ResolutionDiagnostic(INAPPLICABL
|
|||||||
|
|
||||||
class MixingNamedAndPositionArguments(override val argument: FirExpression) : InapplicableArgumentDiagnostic()
|
class MixingNamedAndPositionArguments(override val argument: FirExpression) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class InferredEmptyIntersectionDiagnostic(
|
||||||
|
val incompatibleTypes: Collection<ConeKotlinType>,
|
||||||
|
val typeVariable: ConeTypeVariable
|
||||||
|
) : ResolutionDiagnostic(INAPPLICABLE)
|
||||||
|
|
||||||
class TooManyArguments(
|
class TooManyArguments(
|
||||||
val argument: FirExpression,
|
val argument: FirExpression,
|
||||||
val function: FirFunction
|
val function: FirFunction
|
||||||
|
|||||||
Vendored
+1
-1
@@ -47,7 +47,7 @@ fun test(i: Inv<Nothing>, iUnit: Inv<Unit>) {
|
|||||||
|
|
||||||
if (iUnit is String) {
|
if (iUnit is String) {
|
||||||
launch {
|
launch {
|
||||||
run(A.flexible(iUnit)) { 42 }
|
run(A.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>flexible<!>(iUnit)) { 42 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
class In<in T>
|
||||||
|
class Out<out T>
|
||||||
|
|
||||||
|
class A
|
||||||
|
class B
|
||||||
|
|
||||||
|
fun <K> select(x: K, y: K): K = x
|
||||||
|
fun <V> genericIn(x: In<V>) {}
|
||||||
|
fun <V> genericOut(x: Out<V>) {}
|
||||||
|
|
||||||
|
fun test1(a: In<A>, b: In<B>) {
|
||||||
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>genericIn<!>(select(a, b))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test2(a: Out<A>, b: Out<B>) {
|
||||||
|
genericOut(select(a, b))
|
||||||
|
}
|
||||||
+2
-2
@@ -11,7 +11,7 @@ object Scope {
|
|||||||
fun <T : Comparable<T>, S : T> greater(x: Bar<in S>, t: T) {}
|
fun <T : Comparable<T>, S : T> greater(x: Bar<in S>, t: T) {}
|
||||||
|
|
||||||
fun test(b: Bar<Long>) {
|
fun test(b: Bar<Long>) {
|
||||||
<!DEBUG_INFO_CALL("fqName: Scope.Nested.greater; typeCall: function")!>greater(b, b)<!>
|
<!DEBUG_INFO_CALL("fqName: Scope.greater; typeCall: function")!>greater(b, b)<!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ object OnlyOne {
|
|||||||
fun <T : Comparable<T>, S : T> greater(x: Bar<in S>, t: T) {}
|
fun <T : Comparable<T>, S : T> greater(x: Bar<in S>, t: T) {}
|
||||||
|
|
||||||
fun test(b: Bar<Long>) {
|
fun test(b: Bar<Long>) {
|
||||||
<!DEBUG_INFO_CALL("fqName: OnlyOne.greater; typeCall: function")!>greater(b, b)<!>
|
<!DEBUG_INFO_CALL("fqName: fqName is unknown; typeCall: unresolved")!><!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>greater<!>(b, b)<!>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+4
-4
@@ -164,10 +164,10 @@ fun main() {
|
|||||||
select({ x, y -> x.inv() + y.toByte() }, id { x: Int, y -> y.toByte() }, id { x, y: Number -> x.inv() })
|
select({ x, y -> x.inv() + y.toByte() }, id { x: Int, y -> y.toByte() }, id { x, y: Number -> x.inv() })
|
||||||
|
|
||||||
// Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types
|
// Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types
|
||||||
takeLambdas({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { x: Int -> }, { x: Nothing -> x })
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeLambdas<!>({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { x: Int -> }, { x: Nothing -> x })
|
||||||
takeLambdas({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { } as (Int) -> Unit, { x: Nothing -> x })
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeLambdas<!>({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { } as (Int) -> Unit, { x: Nothing -> x })
|
||||||
takeLambdas({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { } as (Nothing) -> Unit, { x: Int -> x })
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeLambdas<!>({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { } as (Nothing) -> Unit, { x: Int -> x })
|
||||||
takeLambdas({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { } as (Int) -> Unit, { } as (Nothing) -> Unit)
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeLambdas<!>({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>it<!> }, { } as (Int) -> Unit, { } as (Nothing) -> Unit)
|
||||||
|
|
||||||
// Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types; dependent type parameters
|
// Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types; dependent type parameters
|
||||||
takeLambdasWithDirectlyDependentTypeParameters({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!> }, { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!> }, { x: Int -> x })
|
takeLambdasWithDirectlyDependentTypeParameters({ <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!> }, { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>it<!> }, { x: Int -> x })
|
||||||
|
|||||||
Vendored
-13
@@ -1,13 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
|
||||||
|
|
||||||
abstract class Foo<T>
|
|
||||||
|
|
||||||
abstract class Bar<T> : Foo<T>(), Comparable<Bar<T>>
|
|
||||||
|
|
||||||
fun <T : Comparable<T>, S : T> greater(x: Bar<in S>, t: T): Int = 0
|
|
||||||
fun <T : Comparable<T>, S : T> greater(x: Bar<in S>, other: Foo<T>): String = ""
|
|
||||||
|
|
||||||
fun test(b: Bar<Long>) {
|
|
||||||
val result = <!OVERLOAD_RESOLUTION_AMBIGUITY!>greater<!>(b, b)
|
|
||||||
<!DEBUG_INFO_EXPRESSION_TYPE("ERROR CLASS: Ambiguity: greater, [/greater, /greater]")!>result<!>
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||||
|
|
||||||
abstract class Foo<T>
|
abstract class Foo<T>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||||
|
class Foo<T>
|
||||||
|
|
||||||
|
class Bar<T> {
|
||||||
|
fun <S : T> takeFoo(foo: Foo<in S>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val foo = Foo<Int>()
|
||||||
|
Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||||
|
open class A<T1, T2> {}
|
||||||
|
class B {
|
||||||
|
fun <T1: Number, T2: A<Float, T1>> foo(x1: T2, x2: T1) {}
|
||||||
|
}
|
||||||
|
class C<T: D, T2>(val x: T, val y: T2) {
|
||||||
|
fun test() {
|
||||||
|
B().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>foo<!>(x, foo())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
open class D: A<Float, Number>()
|
||||||
|
fun <T: <!FINAL_UPPER_BOUND!>String<!>> foo(): T {
|
||||||
|
return "" <!UNCHECKED_CAST!>as T<!> // this cast is safe because String is final.
|
||||||
|
}
|
||||||
|
fun main() {
|
||||||
|
C(D(), 10.5).test()
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||||
|
interface Base
|
||||||
|
|
||||||
|
class DoesNotImplementBase
|
||||||
|
|
||||||
|
fun <T, V> exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val func: (DoesNotImplementBase) -> Unit = { }
|
||||||
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>exampleGenericFunction<!>(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||||
|
open class Foo
|
||||||
|
inline fun <reified T : Foo> g(): T? = null
|
||||||
|
|
||||||
|
inline fun <R> f(block: ()->R?): R? {
|
||||||
|
return block()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>f<!><Int> { g() }
|
||||||
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@ fun testElvis(a: Int?, b: Int?) {
|
|||||||
if (a != null) {
|
if (a != null) {
|
||||||
doInt(b ?: a)
|
doInt(b ?: a)
|
||||||
}
|
}
|
||||||
doList(getList() ?: emptyListOfA()) //should be an error
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>doList<!>(getList() ?: emptyListOfA()) //should be an error
|
||||||
doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed
|
doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ fun <T: A> emptyNullableListOfA(): List<T>? = null
|
|||||||
//-------------------------------
|
//-------------------------------
|
||||||
|
|
||||||
fun testExclExcl() {
|
fun testExclExcl() {
|
||||||
doList(emptyNullableListOfA()!!) //should be an error here
|
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>doList<!>(emptyNullableListOfA()!!) //should be an error here
|
||||||
val l: List<Int> = <!INITIALIZER_TYPE_MISMATCH, NEW_INFERENCE_ERROR!>id(emptyNullableListOfA()!!)<!>
|
val l: List<Int> = <!INITIALIZER_TYPE_MISMATCH, NEW_INFERENCE_ERROR!>id(emptyNullableListOfA()!!)<!>
|
||||||
|
|
||||||
doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase)
|
doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase)
|
||||||
|
|||||||
Reference in New Issue
Block a user