[FE] Make dynamic a suitable resulted type
This fixes a FIR-specific issue where a type variable is inferred to Any instead of dynamic. K1 wasn't affected because of a FIR-specific condition in ResultTypeResolver. #KT-57962 Fixed
This commit is contained in:
committed by
Space Team
parent
50841e7cb0
commit
6972391185
+1
-1
@@ -30,7 +30,7 @@ class TrivialConstraintTypeInferenceOracle private constructor(context: TypeSyst
|
||||
fun isSuitableResultedType(
|
||||
resultType: KotlinTypeMarker
|
||||
): Boolean {
|
||||
return !resultType.typeConstructor().isNothingConstructor()
|
||||
return !resultType.typeConstructor().isNothingConstructor() || (isK2 && resultType.isDynamic())
|
||||
}
|
||||
|
||||
// It's possible to generate Nothing-like constraints inside incorporation mechanism:
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// FIR_DUMP
|
||||
// DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER, -UNUSED_VARIABLE
|
||||
|
||||
fun foo() {
|
||||
val x1: Any = arrayOf<String>().fold("") { res, key ->
|
||||
res.length
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>res<!>
|
||||
}
|
||||
val x3: Any = arrayOf<String>().fold(js("({})")) { res, key ->
|
||||
res[key] = "hello"
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing..kotlin.Any?!")!>res<!>
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
FILE: setOperatorOnDynamic.fir.kt
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
lval x1: R|kotlin/Any| = R|kotlin/arrayOf|<R|kotlin/String|>().R|kotlin/collections/fold|<R|kotlin/String|, R|kotlin/String|>(String(), <L> = fold@fun <anonymous>(res: R|kotlin/String|, key: R|kotlin/String|): R|kotlin/String| <inline=Inline, kind=UNKNOWN> {
|
||||
R|<local>/res|.R|kotlin/String.length|
|
||||
^ R|<local>/res|
|
||||
}
|
||||
)
|
||||
lval x3: R|kotlin/Any| = R|kotlin/arrayOf|<R|kotlin/String|>().R|kotlin/collections/fold|<R|kotlin/String|, R|dynamic|>(R|kotlin/js/js|(String(({}))), <L> = fold@fun <anonymous>(res: R|dynamic|, key: R|kotlin/String|): R|dynamic| <inline=Inline, kind=UNKNOWN> {
|
||||
R|<local>/res|.R|<dynamic>/set|(vararg(R|<local>/key|, String(hello)))
|
||||
^ R|<local>/res|
|
||||
}
|
||||
)
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// FIR_DUMP
|
||||
// DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER, -UNUSED_VARIABLE
|
||||
|
||||
fun foo() {
|
||||
val x1: Any = arrayOf<String>().fold("") { res, key ->
|
||||
res.length
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>res<!>
|
||||
}
|
||||
val x3: Any = arrayOf<String>().fold(js("({})")) { res, key ->
|
||||
res[key] = "hello"
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>res<!>
|
||||
}
|
||||
}
|
||||
+6
@@ -373,6 +373,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setOperatorOnDynamic.kt")
|
||||
public void testSetOperatorOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/setOperatorOnDynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCast.kt")
|
||||
public void testSmartCast() throws Exception {
|
||||
|
||||
+6
@@ -374,6 +374,12 @@ public class FirPsiJsOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiJ
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setOperatorOnDynamic.kt")
|
||||
public void testSetOperatorOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/setOperatorOnDynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartCast.kt")
|
||||
public void testSmartCast() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user