[NI] Don't replace context dependency for blocks with expected type
#KT-35702 Fixed
This commit is contained in:
Generated
+5
@@ -9933,6 +9933,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35702.kt")
|
||||||
|
public void testKt35702() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt35702.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6175.kt")
|
@TestMetadata("kt6175.kt")
|
||||||
public void testKt6175() throws Exception {
|
public void testKt6175() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
|
||||||
|
|||||||
+1
-6
@@ -327,12 +327,7 @@ public class ExpressionTypingServices {
|
|||||||
expectedType = context.expectedType;
|
expectedType = context.expectedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextDependency dependency = context.contextDependency;
|
return blockLevelVisitor.getTypeInfo(statementExpression, context.replaceExpectedType(expectedType), true);
|
||||||
if (getLanguageVersionSettings().supportsFeature(LanguageFeature.NewInference)) {
|
|
||||||
dependency = ContextDependency.INDEPENDENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return blockLevelVisitor.getTypeInfo(statementExpression, context.replaceExpectedType(expectedType).replaceContextDependency(dependency), true);
|
|
||||||
}
|
}
|
||||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) &&
|
if (context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) &&
|
||||||
statementExpression instanceof KtLambdaExpression) {
|
statementExpression instanceof KtLambdaExpression) {
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNCHECKED_CAST -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER
|
||||||
|
// !WITH_NEW_INFERENCE
|
||||||
|
// ISSUE: KT-35702
|
||||||
|
|
||||||
|
interface A
|
||||||
|
|
||||||
|
fun <T> uncheckedCast(value: Any?): T = value as T
|
||||||
|
|
||||||
|
fun <K> select(x: K, y: K): K = x
|
||||||
|
|
||||||
|
fun <T : A> test_1(b: Boolean, s: String) {
|
||||||
|
val result: (A) -> T = if (b) {
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
} else {
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : A> test_2(b: Boolean, s: String) {
|
||||||
|
val result: (A) -> T = if (b) {
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
} else {
|
||||||
|
{ a -> uncheckedCast(s) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : A> test_3(b: Boolean, s: String) {
|
||||||
|
val result: (A) -> T = if (b) {
|
||||||
|
{ a -> uncheckedCast(s) }
|
||||||
|
} else {
|
||||||
|
{ a -> uncheckedCast(s) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : A> test_4(s: String) {
|
||||||
|
val result: (A) -> T = select(
|
||||||
|
{ a: A -> uncheckedCast(s) },
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNCHECKED_CAST -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER
|
||||||
|
// !WITH_NEW_INFERENCE
|
||||||
|
// ISSUE: KT-35702
|
||||||
|
|
||||||
|
interface A
|
||||||
|
|
||||||
|
fun <T> uncheckedCast(value: Any?): T = value as T
|
||||||
|
|
||||||
|
fun <K> select(x: K, y: K): K = x
|
||||||
|
|
||||||
|
fun <T : A> test_1(b: Boolean, s: String) {
|
||||||
|
val result: (A) -> T = if (b) {
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
} else {
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : A> test_2(b: Boolean, s: String) {
|
||||||
|
val result: (A) -> T = if (b) {
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
} else {
|
||||||
|
{ a -> uncheckedCast(s) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : A> test_3(b: Boolean, s: String) {
|
||||||
|
val result: (A) -> T = if (b) {
|
||||||
|
{ a -> uncheckedCast(s) }
|
||||||
|
} else {
|
||||||
|
{ a -> uncheckedCast(s) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : A> test_4(s: String) {
|
||||||
|
val result: (A) -> T = select(
|
||||||
|
{ a: A -> uncheckedCast(s) },
|
||||||
|
{ a: A -> uncheckedCast(s) }
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ K> select(/*0*/ x: K, /*1*/ y: K): K
|
||||||
|
public fun </*0*/ T : A> test_1(/*0*/ b: kotlin.Boolean, /*1*/ s: kotlin.String): kotlin.Unit
|
||||||
|
public fun </*0*/ T : A> test_2(/*0*/ b: kotlin.Boolean, /*1*/ s: kotlin.String): kotlin.Unit
|
||||||
|
public fun </*0*/ T : A> test_3(/*0*/ b: kotlin.Boolean, /*1*/ s: kotlin.String): kotlin.Unit
|
||||||
|
public fun </*0*/ T : A> test_4(/*0*/ s: kotlin.String): kotlin.Unit
|
||||||
|
public fun </*0*/ T> uncheckedCast(/*0*/ value: kotlin.Any?): T
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -9940,6 +9940,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35702.kt")
|
||||||
|
public void testKt35702() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt35702.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6175.kt")
|
@TestMetadata("kt6175.kt")
|
||||||
public void testKt6175() throws Exception {
|
public void testKt6175() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
|
||||||
|
|||||||
Generated
+5
@@ -9935,6 +9935,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt35702.kt")
|
||||||
|
public void testKt35702() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/kt35702.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6175.kt")
|
@TestMetadata("kt6175.kt")
|
||||||
public void testKt6175() throws Exception {
|
public void testKt6175() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user