FIR: Fix incorrect type of block generated for inc operator
Previously, it was obtained from expected type of a variable being assigned,
but it's better to use the type of resulting expression
Initially this part was brought in 4ab0897d7d,
but as we see in commit message and tests it was all about unit-coercion
This commit is contained in:
committed by
teamcityserver
parent
a7859e0332
commit
c0b6a593e0
+6
@@ -21075,6 +21075,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("incForAssignmentSmartCast.kt")
|
||||
public void testIncForAssignmentSmartCast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/incForAssignmentSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InconsistentGetSet.kt")
|
||||
public void testInconsistentGetSet() throws Exception {
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>kotlin.jvm.functions.Function0<!>
|
||||
|
||||
val x: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN, PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Function0<Int><!> = <!INITIALIZER_TYPE_MISMATCH!>{ 42 }<!>
|
||||
val x: <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Function0<Int><!> = <!INITIALIZER_TYPE_MISMATCH!>{ 42 }<!>
|
||||
|
||||
val y: Function1<String, String> = { it }
|
||||
|
||||
class MyFunction : Function2<Int, String, Unit> {
|
||||
override fun invoke(p1: Int, p2: String) {}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -21075,6 +21075,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("incForAssignmentSmartCast.kt")
|
||||
public void testIncForAssignmentSmartCast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/incForAssignmentSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InconsistentGetSet.kt")
|
||||
public void testInconsistentGetSet() throws Exception {
|
||||
|
||||
+6
@@ -21075,6 +21075,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("incForAssignmentSmartCast.kt")
|
||||
public void testIncForAssignmentSmartCast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/incForAssignmentSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InconsistentGetSet.kt")
|
||||
public void testInconsistentGetSet() throws Exception {
|
||||
|
||||
+2
-2
@@ -408,8 +408,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
TransformData.Data(value)
|
||||
}
|
||||
block.transformOtherChildren(transformer, data)
|
||||
if (data is ResolutionMode.WithExpectedType && data.expectedTypeRef is FirResolvedTypeRef) {
|
||||
// Top-down propagation: from the explicit type of the enclosing declaration to the block type
|
||||
if (data is ResolutionMode.WithExpectedType && data.expectedTypeRef.coneTypeSafe<ConeKotlinType>()?.isUnitOrFlexibleUnit == true) {
|
||||
// Unit-coercion
|
||||
block.resultType = data.expectedTypeRef
|
||||
} else {
|
||||
// Bottom-up propagation: from the return type of the last expression in the block to the block type
|
||||
|
||||
@@ -41,9 +41,7 @@ suspend fun box() {
|
||||
// test.kt:16 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $this$extensionFun$iv$iv:AtomicInt=AtomicInt, $i$f$extensionFun:int=0:int
|
||||
// test.kt:20 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int
|
||||
// test.kt:21 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $i$a$-suspendCoroutineUninterceptedOrReturn-TestKt$suspendBar$2$iv:int=0:int
|
||||
// EXPECTATIONS CLASSIC_FRONTEND
|
||||
// test.kt:22 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $i$a$-suspendCoroutineUninterceptedOrReturn-TestKt$suspendBar$2$iv:int=0:int
|
||||
// EXPECTATIONS
|
||||
// test.kt:20 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int
|
||||
// test.kt:23 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int
|
||||
// test.kt:26 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null
|
||||
|
||||
Vendored
+2
-2
@@ -6,8 +6,8 @@ fun test() {
|
||||
val x = <!ANONYMOUS_FUNCTION_WITH_NAME!>fun named1(x: Int): Int { return 1 }<!>
|
||||
x <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Function1<Int, Int>>() }
|
||||
|
||||
foo { fun named2(): Int {return 1} }
|
||||
foo({ fun named3() = 1 })
|
||||
foo { <!ARGUMENT_TYPE_MISMATCH!>fun named2(): Int {return 1}<!> }
|
||||
foo({ <!ARGUMENT_TYPE_MISMATCH!>fun named3() = 1<!> })
|
||||
|
||||
val x1 =
|
||||
if (1 == 1)
|
||||
|
||||
Vendored
+1
-1
@@ -155,7 +155,7 @@ fun main() {
|
||||
select(id(id(fun(x: String, y: String) { }), <!TOO_MANY_ARGUMENTS!>fun String.(x: String) {}<!>), { x, y -> x })
|
||||
val x26: Int.(String) -> Int = fun (x: String) = 10 // it must be error, see KT-38439
|
||||
// Receiver must be specified in anonymous function declaration
|
||||
val x27: Int.(String) -> Int = id(<!ARGUMENT_TYPE_MISMATCH!>fun (x: String) = 10<!>)
|
||||
val x27: Int.(String) -> Int = id(<!ARGUMENT_TYPE_MISMATCH, ARGUMENT_TYPE_MISMATCH!>fun (x: String) = 10<!>)
|
||||
select(id<Int.(String) -> Unit> {}, { x: Int, y: String -> x })
|
||||
|
||||
// Inferring lambda parameter types by partially specified parameter types of other lambdas
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class A : (vararg Int)->Unit {
|
||||
}
|
||||
|
||||
val prop: (vararg x: Int)->Unit
|
||||
get(): (<!WRONG_MODIFIER_CONTAINING_DECLARATION, WRONG_MODIFIER_CONTAINING_DECLARATION!>vararg<!> x: Int)->Unit = {}
|
||||
get(): (<!WRONG_MODIFIER_CONTAINING_DECLARATION!>vararg<!> x: Int)->Unit = {}
|
||||
}
|
||||
|
||||
val allProhibited: (<!REDUNDANT_MODIFIER, WRONG_MODIFIER_TARGET!>abstract<!>
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// SKIP_TXT
|
||||
var c = 1
|
||||
|
||||
fun nullable(): Int? = null
|
||||
|
||||
fun foo(): Int {
|
||||
var x = nullable()
|
||||
if (x == null) {
|
||||
x = c++
|
||||
}
|
||||
|
||||
return x
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// SKIP_TXT
|
||||
var c = 1
|
||||
|
||||
fun nullable(): Int? = null
|
||||
|
||||
fun foo(): Int {
|
||||
var x = nullable()
|
||||
if (x == null) {
|
||||
x = c++
|
||||
}
|
||||
|
||||
return <!DEBUG_INFO_SMARTCAST!>x<!>
|
||||
}
|
||||
+4
-4
@@ -3,10 +3,10 @@ fun main() {
|
||||
var v = 1
|
||||
val b : String = <!INITIALIZER_TYPE_MISMATCH!>v<!>;
|
||||
val f : String = <!INITIALIZER_TYPE_MISMATCH!>a!!<!>;
|
||||
val g : String = v++;
|
||||
val g1 : String = ++v;
|
||||
val h : String = v--;
|
||||
val h1 : String = --v;
|
||||
val g : String = <!INITIALIZER_TYPE_MISMATCH!>v++<!>;
|
||||
val g1 : String = <!INITIALIZER_TYPE_MISMATCH!>++v<!>;
|
||||
val h : String = <!INITIALIZER_TYPE_MISMATCH!>v--<!>;
|
||||
val h1 : String = <!INITIALIZER_TYPE_MISMATCH!>--v<!>;
|
||||
val i : String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>!true<!>;
|
||||
val j : String = <!INITIALIZER_TYPE_MISMATCH!>foo@ true<!>;
|
||||
val k : String = <!INITIALIZER_TYPE_MISMATCH!>foo@ bar@ true<!>;
|
||||
|
||||
@@ -2,8 +2,8 @@ FILE fqName:<root> fileName:/coercionToUnit.kt
|
||||
PROPERTY name:test1 visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test1 type:kotlin.Function0<kotlin.Unit> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
FUN_EXPR type=kotlin.Function0<kotlin.Int> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Int
|
||||
FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
CONST Int type=kotlin.Int value=42
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
val test1: Function0<Unit>
|
||||
field = local fun <anonymous>(): Int {
|
||||
field = local fun <anonymous>() {
|
||||
42 /*~> Unit */
|
||||
}
|
||||
|
||||
|
||||
@@ -11,5 +11,4 @@ FILE fqName:<root> fileName:/lambdaReturningUnit.kt
|
||||
block: FUN_EXPR type=kotlin.Function0<kotlin.Any?> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Any?
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Any? declared in <root>.box'
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
|
||||
@@ -4,7 +4,7 @@ inline fun flaf(block: Function0<Any?>) {
|
||||
|
||||
suspend fun box() {
|
||||
flaf(block = local fun <anonymous>(): Any? {
|
||||
return Unit
|
||||
Unit
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Generated
+6
@@ -21081,6 +21081,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/compareToNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("incForAssignmentSmartCast.kt")
|
||||
public void testIncForAssignmentSmartCast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/operatorsOverloading/incForAssignmentSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("InconsistentGetSet.kt")
|
||||
public void testInconsistentGetSet() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user