Fix bare typed smartcasts in NI
Star projections should be replaced with star projections not for their expansions See the test
This commit is contained in:
+1
@@ -25,6 +25,7 @@ abstract class AbstractFirOldFrontendDiagnosticsTest : AbstractFirDiagnosticsTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
||||||
|
if (testFiles.any { it.directives.containsKey("FIR_IGNORE") }) return
|
||||||
val failure: AssertionError? = try {
|
val failure: AssertionError? = try {
|
||||||
for ((_, firFiles) in firFilesPerSession) {
|
for ((_, firFiles) in firFilesPerSession) {
|
||||||
doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, gc = false)
|
doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, gc = false)
|
||||||
|
|||||||
Generated
+5
@@ -8301,6 +8301,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
|
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")
|
@TestMetadata("commonSupertypeContravariant.kt")
|
||||||
public void testCommonSupertypeContravariant() throws Exception {
|
public void testCommonSupertypeContravariant() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
||||||
|
|||||||
@@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.types;
|
package org.jetbrains.kotlin.types;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.utils.CollectionsKt;
|
import org.jetbrains.kotlin.utils.CollectionsKt;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -100,9 +98,10 @@ public class TypeUnifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Foo ~ X => x |-> Foo
|
// Foo ~ X => x |-> Foo
|
||||||
|
// * ~ X => x |-> *
|
||||||
TypeConstructor maybeVariable = withVariables.getConstructor();
|
TypeConstructor maybeVariable = withVariables.getConstructor();
|
||||||
if (isVariable.test(maybeVariable)) {
|
if (isVariable.test(maybeVariable)) {
|
||||||
result.put(maybeVariable, new TypeProjectionImpl(knownProjectionKind, known));
|
result.put(maybeVariable, knownProjection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
@@ -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<E> : FirElement where E : FirSymbolOwner<E>, E : FirDeclaration
|
||||||
|
|
||||||
|
interface FirCallableDeclaration<F : FirCallableDeclaration<F>> : FirDeclaration, FirSymbolOwner<F>
|
||||||
|
|
||||||
|
interface FirBasedSymbol<E> where E : FirSymbolOwner<E>, E : FirDeclaration
|
||||||
|
interface AbstractFirBasedSymbol<E> : FirBasedSymbol<E> where E : FirSymbolOwner<E>, E : FirDeclaration
|
||||||
|
|
||||||
|
interface FirVariable<F : FirVariable<F>> : FirCallableDeclaration<F>, FirDeclaration, FirStatement
|
||||||
|
|
||||||
|
interface FirCallableSymbol<D : FirCallableDeclaration<D>> : AbstractFirBasedSymbol<D>
|
||||||
|
interface FirVariableSymbol<D : FirVariable<D>> : FirCallableSymbol<D>
|
||||||
|
interface FirPropertySymbol : FirVariableSymbol<FirProperty>
|
||||||
|
|
||||||
|
interface FirCallableMemberDeclaration<F : FirCallableMemberDeclaration<F>> : FirCallableDeclaration<F>, FirMemberDeclaration
|
||||||
|
|
||||||
|
interface FirProperty : FirVariable<FirProperty>, FirCallableMemberDeclaration<FirProperty>
|
||||||
|
|
||||||
|
fun <D> AbstractFirBasedSymbol<D>.phasedFir(): D where D : FirDeclaration, D : FirSymbolOwner<D> = TODO()
|
||||||
|
|
||||||
|
fun foo(coneSymbol: AbstractFirBasedSymbol<*>) {
|
||||||
|
if (coneSymbol !is FirVariableSymbol) return
|
||||||
|
// For bare types, smart cast should be performed to FirVariableSymbol<*> not to FirVariableSymbol<out FirVariable<*>>
|
||||||
|
coneSymbol.phasedFir() checkType { _<FirVariable<*>>() }
|
||||||
|
|
||||||
|
if (coneSymbol !is FirPropertySymbol) return
|
||||||
|
coneSymbol.phasedFir() checkType { _<FirProperty>() }
|
||||||
|
}
|
||||||
@@ -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<E> : FirElement where E : FirSymbolOwner<E>, E : FirDeclaration
|
||||||
|
|
||||||
|
interface FirCallableDeclaration<F : FirCallableDeclaration<F>> : FirDeclaration, FirSymbolOwner<F>
|
||||||
|
|
||||||
|
interface FirBasedSymbol<E> where E : FirSymbolOwner<E>, E : FirDeclaration
|
||||||
|
interface AbstractFirBasedSymbol<E> : FirBasedSymbol<E> where E : FirSymbolOwner<E>, E : FirDeclaration
|
||||||
|
|
||||||
|
interface FirVariable<F : FirVariable<F>> : FirCallableDeclaration<F>, FirDeclaration, FirStatement
|
||||||
|
|
||||||
|
interface FirCallableSymbol<D : FirCallableDeclaration<D>> : AbstractFirBasedSymbol<D>
|
||||||
|
interface FirVariableSymbol<D : FirVariable<D>> : FirCallableSymbol<D>
|
||||||
|
interface FirPropertySymbol : FirVariableSymbol<FirProperty>
|
||||||
|
|
||||||
|
interface FirCallableMemberDeclaration<F : FirCallableMemberDeclaration<F>> : FirCallableDeclaration<F>, FirMemberDeclaration
|
||||||
|
|
||||||
|
interface FirProperty : FirVariable<FirProperty>, FirCallableMemberDeclaration<FirProperty>
|
||||||
|
|
||||||
|
fun <D> AbstractFirBasedSymbol<D>.phasedFir(): D where D : FirDeclaration, D : FirSymbolOwner<D> = TODO()
|
||||||
|
|
||||||
|
fun foo(coneSymbol: AbstractFirBasedSymbol<*>) {
|
||||||
|
if (coneSymbol !is FirVariableSymbol) return
|
||||||
|
// For bare types, smart cast should be performed to FirVariableSymbol<*> not to FirVariableSymbol<out FirVariable<*>>
|
||||||
|
coneSymbol.phasedFir() checkType { _<FirVariable<*>>() }
|
||||||
|
|
||||||
|
if (coneSymbol !is FirPropertySymbol) return
|
||||||
|
coneSymbol.phasedFir() checkType { _<FirProperty>() }
|
||||||
|
}
|
||||||
@@ -8308,6 +8308,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
|
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")
|
@TestMetadata("commonSupertypeContravariant.kt")
|
||||||
public void testCommonSupertypeContravariant() throws Exception {
|
public void testCommonSupertypeContravariant() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
||||||
|
|||||||
Generated
+5
@@ -8303,6 +8303,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
|
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")
|
@TestMetadata("commonSupertypeContravariant.kt")
|
||||||
public void testCommonSupertypeContravariant() throws Exception {
|
public void testCommonSupertypeContravariant() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user