[FE 1.0] Don't report CAST_NEVER_SUCCEEDS on stub types

^KT-49829 Fixed
This commit is contained in:
Victor Petukhov
2021-12-17 10:29:14 +03:00
committed by teamcity
parent 37d163d417
commit 8e2b90b5db
10 changed files with 71 additions and 11 deletions
@@ -13944,6 +13944,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt");
}
@Test
@TestMetadata("kt49829.kt")
public void testKt49829() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt49829.kt");
}
@Test
@TestMetadata("labaledCall.kt")
public void testLabaledCall() throws Exception {
@@ -13944,6 +13944,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt");
}
@Test
@TestMetadata("kt49829.kt")
public void testKt49829() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt49829.kt");
}
@Test
@TestMetadata("labaledCall.kt")
public void testLabaledCall() throws Exception {
@@ -76,6 +76,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.ResolveConstruct;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
import org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperKt;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import org.jetbrains.kotlin.util.OperatorNameConventions;
import java.util.Collection;
@@ -372,7 +373,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return;
}
if (!CastDiagnosticsUtil.isCastPossible(actualType, targetType, components.platformToKotlinClassMapper)) {
if (!CastDiagnosticsUtil.isCastPossible(actualType, targetType, components.platformToKotlinClassMapper) && !TypeUtilsKt.isStubType(actualType)) {
context.trace.report(CAST_NEVER_SUCCEEDS.on(expression.getOperationReference()));
return;
}
@@ -0,0 +1,12 @@
// WITH_STDLIB
// For FIR: see KT-50293
fun main() {
val list = buildList {
add("one")
add("two")
val secondParameter = get(1)
println(secondParameter <!USELESS_CAST!>as String<!>) // WARNING: [CAST_NEVER_SUCCEEDS] This cast can never succeed
}
}
@@ -0,0 +1,12 @@
// WITH_STDLIB
// For FIR: see KT-50293
fun main() {
val list = buildList {
add("one")
add("two")
val secondParameter = get(1)
println(secondParameter as String) // WARNING: [CAST_NEVER_SUCCEEDS] This cast can never succeed
}
}
@@ -0,0 +1,3 @@
package
public fun main(): kotlin.Unit
@@ -13950,6 +13950,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt");
}
@Test
@TestMetadata("kt49829.kt")
public void testKt49829() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt49829.kt");
}
@Test
@TestMetadata("labaledCall.kt")
public void testLabaledCall() throws Exception {