From c16ae81a4805d63f48b9e8cd3c36ac839ec06486 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Fri, 11 Feb 2022 12:25:06 +0300 Subject: [PATCH] [FIR] Report errors for upper bounded type variables by an empty intersection type ^KT-51221 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 24 +++++++++++++++++++ ...irOldFrontendDiagnosticsTestGenerated.java | 24 +++++++++++++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 24 +++++++++++++++++++ .../diagnostics/FirDiagnosticsList.kt | 6 +++++ .../fir/analysis/diagnostics/FirErrors.kt | 1 + .../diagnostics/FirErrorsDefaultMessages.kt | 7 ++++++ .../coneDiagnosticToFirDiagnostic.kt | 23 ++++++++++++++++++ ...rCallCompletionResultsWriterTransformer.kt | 12 ++++++---- .../fir/resolve/calls/ResolutionDiagnostic.kt | 6 +++++ .../coercionToUnitWithNothingType.fir.kt | 2 +- ...tFromCovariantAndContravariantTypes.fir.kt | 21 ++++++++++++++++ ...nVariableHasComplexIntersectionType.fir.kt | 4 ++-- .../postponedArgumentsAnalysis/basic.fir.kt | 8 +++---- ...rsectionTypesWithContravariantTypes.fir.kt | 13 ---------- ...intersectionTypesWithContravariantTypes.kt | 1 + .../tests/inference/kt45461.fir.kt | 11 +++++++++ .../tests/inference/kt48765.fir.kt | 17 +++++++++++++ .../tests/inference/kt48935.fir.kt | 13 ++++++++++ .../tests/inference/kt49661.fir.kt | 11 +++++++++ .../specialConstructions/elvisAsCall.fir.kt | 2 +- .../exclExclAsCall.fir.kt | 2 +- 21 files changed, 206 insertions(+), 26 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt45461.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48765.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt49661.fir.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 122188cb409..90cb98d4aef 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -13834,6 +13834,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag 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 @TestMetadata("kt46515.kt") public void testKt46515() throws Exception { @@ -13846,6 +13852,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag 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 @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { @@ -13858,6 +13876,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag 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 @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index b2c3130bfb8..cdf56cebf40 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -13834,6 +13834,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti 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 @TestMetadata("kt46515.kt") public void testKt46515() throws Exception { @@ -13846,6 +13852,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti 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 @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { @@ -13858,6 +13876,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti 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 @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 720d4a6fd19..a1ca03b08ec 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -13834,6 +13834,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac 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 @TestMetadata("kt46515.kt") public void testKt46515() throws Exception { @@ -13846,6 +13852,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac 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 @TestMetadata("kt49658.kt") public void testKt49658() throws Exception { @@ -13858,6 +13876,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac 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 @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index dff2ad03099..4722ec986d1 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.EffectiveVisibility import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.diagnostics.WhenMissingCase +import org.jetbrains.kotlin.diagnostics.deprecationError2 import org.jetbrains.kotlin.fir.FirModuleData import org.jetbrains.kotlin.fir.PrivateForInline 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(PositioningStrategy.REFERENCED_NAME_BY_QUALIFIED) { parameter("kotlinClass") } + + val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by error { + parameter("typeVariableDescription") + parameter>("incompatibleTypes") + } } val REFLECTION by object : DiagnosticGroup("Reflection") { diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 121a714a0e0..84fd65723ad 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -412,6 +412,7 @@ object FirErrors { val SMARTCAST_IMPOSSIBLE by error4() val REDUNDANT_NULLABLE by warning0(SourceElementPositioningStrategies.REDUNDANT_NULLABLE) val PLATFORM_CLASS_MAPPED_TO_KOTLIN by warning1(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED) + val INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION by error2>() // Reflection val EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED by error1>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index c18d5dd264d..444ca2bd2dc 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -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.INFERENCE_ERROR 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.INITIALIZATION_BEFORE_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_FUNCTION, "Redundant spread (*) operator") 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(THROWABLE_TYPE_MISMATCH, "Throwable type mismatch: actual type is {0}", TO_STRING, NOT_RENDERED) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 839a5e0fe4a..8585baaa53c 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -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.diagnostics.* 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.inference.ConeTypeParameterBasedTypeVariable 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.ConeExpectedTypeConstraintPosition 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.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol @@ -253,6 +255,8 @@ private fun mapInapplicableCandidateError( diagnostic.candidate ) } + is InferredEmptyIntersectionDiagnostic -> + reportInferredIntoEmptyIntersectionError(source, rootCause.typeVariable, rootCause.incompatibleTypes) else -> genericDiagnostic } }.distinct() @@ -388,10 +392,29 @@ private fun ConstraintSystemError.toDiagnostic( position.initialConstraint.asStringWithoutPosition(), ) } + is InferredEmptyIntersection -> { + @Suppress("UNCHECKED_CAST") + reportInferredIntoEmptyIntersectionError( + source, + typeVariable as ConeTypeVariable, + incompatibleTypes as Collection + ) + } else -> null } } +private fun reportInferredIntoEmptyIntersectionError( + source: KtSourceElement, + typeVariable: ConeTypeVariable, + incompatibleTypes: Collection, +): KtDiagnosticWithParameters2>? { + 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.upperConeType: ConeKotlinType get() = upperType as ConeKotlinType diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 9d29241bc9f..54fabddf207 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -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.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer -import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeConstraintSystemHasContradiction -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.diagnostics.* import org.jetbrains.kotlin.fir.resolve.inference.ResolvedLambdaAtom import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider 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.FirTransformer 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.isSuccess import org.jetbrains.kotlin.types.TypeApproximatorConfiguration @@ -856,6 +854,9 @@ class FirCallCompletionResultsWriterTransformer( return varargArgumentsExpression } + private fun FirNamedReferenceWithCandidate.hasAdditionalResolutionErrors(): Boolean = + candidate.system.errors.any { it is InferredEmptyIntersection } + private fun FirNamedReferenceWithCandidate.toResolvedReference(): FirNamedReference { val errorDiagnostic = when { this is FirErrorReferenceWithCandidate -> this.diagnostic @@ -867,6 +868,9 @@ class FirCallCompletionResultsWriterTransformer( 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 } diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt index 4828b3fc2a1..7ff697c7cad 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol 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.calls.inference.model.ConstraintSystemError 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 InferredEmptyIntersectionDiagnostic( + val incompatibleTypes: Collection, + val typeVariable: ConeTypeVariable +) : ResolutionDiagnostic(INAPPLICABLE) + class TooManyArguments( val argument: FirExpression, val function: FirFunction diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt index 22d94ca5740..129443ceb90 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitWithNothingType.fir.kt @@ -47,7 +47,7 @@ fun test(i: Inv, iUnit: Inv) { if (iUnit is String) { launch { - run(A.flexible(iUnit)) { 42 } + run(A.flexible(iUnit)) { 42 } } } } diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt new file mode 100644 index 00000000000..ffdca6183e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/selectFromCovariantAndContravariantTypes.fir.kt @@ -0,0 +1,21 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class In +class Out + +class A +class B + +fun select(x: K, y: K): K = x +fun genericIn(x: In) {} +fun genericOut(x: Out) {} + +fun test1(a: In, b: In) { + genericIn(select(a, b)) +} + +fun test2(a: Out, b: Out) { + genericOut(select(a, b)) +} diff --git a/compiler/testData/diagnostics/tests/inference/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt b/compiler/testData/diagnostics/tests/inference/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt index 460d6e39714..bcca7b21765 100644 --- a/compiler/testData/diagnostics/tests/inference/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/compatibilityResolveWhenVariableHasComplexIntersectionType.fir.kt @@ -11,7 +11,7 @@ object Scope { fun , S : T> greater(x: Bar, t: T) {} fun test(b: Bar) { - greater(b, b) + greater(b, b) } } } @@ -20,7 +20,7 @@ object OnlyOne { fun , S : T> greater(x: Bar, t: T) {} fun test(b: Bar) { - greater(b, b) + greater(b, b) } } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt index d2dfa2a385d..2e5fa6c12bd 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt @@ -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() }) // Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types - takeLambdas({ it }, { x: Int -> }, { x: Nothing -> x }) - takeLambdas({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) - takeLambdas({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) - takeLambdas({ it }, { } as (Int) -> Unit, { } as (Nothing) -> Unit) + takeLambdas({ it }, { x: Int -> }, { x: Nothing -> x }) + takeLambdas({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) + takeLambdas({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) + takeLambdas({ 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 takeLambdasWithDirectlyDependentTypeParameters({ it }, { it }, { x: Int -> x }) diff --git a/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.fir.kt deleted file mode 100644 index b12d836a9b2..00000000000 --- a/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.fir.kt +++ /dev/null @@ -1,13 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION - -abstract class Foo - -abstract class Bar : Foo(), Comparable> - -fun , S : T> greater(x: Bar, t: T): Int = 0 -fun , S : T> greater(x: Bar, other: Foo): String = "" - -fun test(b: Bar) { - val result = greater(b, b) - result -} diff --git a/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.kt b/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.kt index 30f4a95028c..27d0c9ac623 100644 --- a/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/intersectionTypesWithContravariantTypes.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION abstract class Foo diff --git a/compiler/testData/diagnostics/tests/inference/kt45461.fir.kt b/compiler/testData/diagnostics/tests/inference/kt45461.fir.kt new file mode 100644 index 00000000000..3986ceffcc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt45461.fir.kt @@ -0,0 +1,11 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +class Foo + +class Bar { + fun takeFoo(foo: Foo) {} +} + +fun main() { + val foo = Foo() + Bar().takeFoo(foo) // error in 1.3.72, no error in 1.4.31 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48765.fir.kt b/compiler/testData/diagnostics/tests/inference/kt48765.fir.kt new file mode 100644 index 00000000000..fc93724b074 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48765.fir.kt @@ -0,0 +1,17 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +open class A {} +class B { + fun > foo(x1: T2, x2: T1) {} +} +class C(val x: T, val y: T2) { + fun test() { + B().foo(x, foo()) + } +} +open class D: A() +fun String> foo(): T { + return "" as T // this cast is safe because String is final. +} +fun main() { + C(D(), 10.5).test() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935.fir.kt b/compiler/testData/diagnostics/tests/inference/kt48935.fir.kt new file mode 100644 index 00000000000..d7e2cdfc5dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935.fir.kt @@ -0,0 +1,13 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +interface Base + +class DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt49661.fir.kt b/compiler/testData/diagnostics/tests/inference/kt49661.fir.kt new file mode 100644 index 00000000000..696829e1fbd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49661.fir.kt @@ -0,0 +1,11 @@ +// RENDER_DIAGNOSTICS_FULL_TEXT +open class Foo +inline fun g(): T? = null + +inline fun f(block: ()->R?): R? { + return block() +} + +fun main() { + f { g() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt index ecc4fe08214..4f0327d961b 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt @@ -13,7 +13,7 @@ fun testElvis(a: Int?, b: Int?) { if (a != null) { doInt(b ?: a) } - doList(getList() ?: emptyListOfA()) //should be an error + doList(getList() ?: emptyListOfA()) //should be an error doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed } diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt index 9ab0c68ba6d..808c42324ad 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt @@ -12,7 +12,7 @@ fun emptyNullableListOfA(): List? = null //------------------------------- fun testExclExcl() { - doList(emptyNullableListOfA()!!) //should be an error here + doList(emptyNullableListOfA()!!) //should be an error here val l: List = id(emptyNullableListOfA()!!) doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase)