diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirOldFrontendDiagnosticsTest.kt b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirOldFrontendDiagnosticsTest.kt index bdc81d348d3..b8a7352b373 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirOldFrontendDiagnosticsTest.kt +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/AbstractFirOldFrontendDiagnosticsTest.kt @@ -25,6 +25,7 @@ abstract class AbstractFirOldFrontendDiagnosticsTest : AbstractFirDiagnosticsTes } override fun runAnalysis(testDataFile: File, testFiles: List, firFilesPerSession: Map>) { + if (testFiles.any { it.directives.containsKey("FIR_IGNORE") }) return val failure: AssertionError? = try { for ((_, firFiles) in firFilesPerSession) { doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, gc = false) diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 65dfc9b5554..2bf92a94dd9 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -8301,6 +8301,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt"); } + @TestMetadata("bareTypesWithStarProjections.kt") + public void testBareTypesWithStarProjections() throws Exception { + runTest("compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.kt"); + } + @TestMetadata("commonSupertypeContravariant.kt") public void testCommonSupertypeContravariant() throws Exception { runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/TypeUnifier.java b/compiler/frontend/src/org/jetbrains/kotlin/types/TypeUnifier.java index 97ab4957fc9..564a63b73ef 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/TypeUnifier.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/TypeUnifier.java @@ -16,11 +16,9 @@ package org.jetbrains.kotlin.types; -import com.google.common.collect.Maps; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.utils.CollectionsKt; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -100,9 +98,10 @@ public class TypeUnifier { } // Foo ~ X => x |-> Foo + // * ~ X => x |-> * TypeConstructor maybeVariable = withVariables.getConstructor(); if (isVariable.test(maybeVariable)) { - result.put(maybeVariable, new TypeProjectionImpl(knownProjectionKind, known)); + result.put(maybeVariable, knownProjection); return; } diff --git a/compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.fir.kt b/compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.fir.kt new file mode 100644 index 00000000000..6c8fcf68cb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.fir.kt @@ -0,0 +1,40 @@ +// SKIP_TXT +// IGNORE_FIR +// !CHECK_TYPE +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !FIR_IGNORE + +interface FirMemberDeclaration : FirDeclaration +interface TypeConstructorMarker + +interface FirElement +interface FirDeclaration : FirElement +interface FirStatement : FirElement +interface FirSymbolOwner : FirElement where E : FirSymbolOwner, E : FirDeclaration + +interface FirCallableDeclaration> : FirDeclaration, FirSymbolOwner + +interface FirBasedSymbol where E : FirSymbolOwner, E : FirDeclaration +interface AbstractFirBasedSymbol : FirBasedSymbol where E : FirSymbolOwner, E : FirDeclaration + +interface FirVariable> : FirCallableDeclaration, FirDeclaration, FirStatement + +interface FirCallableSymbol> : AbstractFirBasedSymbol +interface FirVariableSymbol> : FirCallableSymbol +interface FirPropertySymbol : FirVariableSymbol + +interface FirCallableMemberDeclaration> : FirCallableDeclaration, FirMemberDeclaration + +interface FirProperty : FirVariable, FirCallableMemberDeclaration + +fun AbstractFirBasedSymbol.phasedFir(): D where D : FirDeclaration, D : FirSymbolOwner = TODO() + +fun foo(coneSymbol: AbstractFirBasedSymbol<*>) { + if (coneSymbol !is FirVariableSymbol) return + // For bare types, smart cast should be performed to FirVariableSymbol<*> not to FirVariableSymbol> + coneSymbol.phasedFir() checkType { _>() } + + if (coneSymbol !is FirPropertySymbol) return + coneSymbol.phasedFir() checkType { _() } +} diff --git a/compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.kt b/compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.kt new file mode 100644 index 00000000000..6c8fcf68cb7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.kt @@ -0,0 +1,40 @@ +// SKIP_TXT +// IGNORE_FIR +// !CHECK_TYPE +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !FIR_IGNORE + +interface FirMemberDeclaration : FirDeclaration +interface TypeConstructorMarker + +interface FirElement +interface FirDeclaration : FirElement +interface FirStatement : FirElement +interface FirSymbolOwner : FirElement where E : FirSymbolOwner, E : FirDeclaration + +interface FirCallableDeclaration> : FirDeclaration, FirSymbolOwner + +interface FirBasedSymbol where E : FirSymbolOwner, E : FirDeclaration +interface AbstractFirBasedSymbol : FirBasedSymbol where E : FirSymbolOwner, E : FirDeclaration + +interface FirVariable> : FirCallableDeclaration, FirDeclaration, FirStatement + +interface FirCallableSymbol> : AbstractFirBasedSymbol +interface FirVariableSymbol> : FirCallableSymbol +interface FirPropertySymbol : FirVariableSymbol + +interface FirCallableMemberDeclaration> : FirCallableDeclaration, FirMemberDeclaration + +interface FirProperty : FirVariable, FirCallableMemberDeclaration + +fun AbstractFirBasedSymbol.phasedFir(): D where D : FirDeclaration, D : FirSymbolOwner = TODO() + +fun foo(coneSymbol: AbstractFirBasedSymbol<*>) { + if (coneSymbol !is FirVariableSymbol) return + // For bare types, smart cast should be performed to FirVariableSymbol<*> not to FirVariableSymbol> + coneSymbol.phasedFir() checkType { _>() } + + if (coneSymbol !is FirPropertySymbol) return + coneSymbol.phasedFir() checkType { _() } +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 8812e7edac4..444c67c36c7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -8308,6 +8308,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt"); } + @TestMetadata("bareTypesWithStarProjections.kt") + public void testBareTypesWithStarProjections() throws Exception { + runTest("compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.kt"); + } + @TestMetadata("commonSupertypeContravariant.kt") public void testCommonSupertypeContravariant() throws Exception { runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 35d0c0f418d..ca669c2af14 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -8303,6 +8303,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt"); } + @TestMetadata("bareTypesWithStarProjections.kt") + public void testBareTypesWithStarProjections() throws Exception { + runTest("compiler/testData/diagnostics/tests/generics/bareTypesWithStarProjections.kt"); + } + @TestMetadata("commonSupertypeContravariant.kt") public void testCommonSupertypeContravariant() throws Exception { runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");