[NI] Don't replace context dependency for blocks with expected type

#KT-35702 Fixed
This commit is contained in:
Dmitriy Novozhilov
2019-12-26 17:32:44 +03:00
parent 4fa5e2d85c
commit 04e567dbf9
7 changed files with 112 additions and 6 deletions
@@ -9933,6 +9933,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
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")
public void testKt6175() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
@@ -327,12 +327,7 @@ public class ExpressionTypingServices {
expectedType = context.expectedType;
}
ContextDependency dependency = context.contextDependency;
if (getLanguageVersionSettings().supportsFeature(LanguageFeature.NewInference)) {
dependency = ContextDependency.INDEPENDENT;
}
return blockLevelVisitor.getTypeInfo(statementExpression, context.replaceExpectedType(expectedType).replaceContextDependency(dependency), true);
return blockLevelVisitor.getTypeInfo(statementExpression, context.replaceExpectedType(expectedType), true);
}
if (context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference) &&
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");
}
@TestMetadata("kt35702.kt")
public void testKt35702() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt35702.kt");
}
@TestMetadata("kt6175.kt")
public void testKt6175() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
@@ -9935,6 +9935,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
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")
public void testKt6175() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");