[FIR] Add equality constraint from expected type for some synthetic function calls
This fixes some cases where we infer some type variable inside one of the branches to Nothing instead of the expected type because Nothing appeared in some other branch. Specifically, we add an equality instead of a subtype constraint during completion of calls to synthetic functions for if/when, try and !!. We don't do it when the call contains a (possibly nested) elvis or is inside the RHS of an assignment. Otherwise, we would prevent some smart-casts. #KT-65882 Fixed
This commit is contained in:
committed by
Space Team
parent
eaef7122f6
commit
69a7bf7f68
Vendored
+2
-2
@@ -29,11 +29,11 @@ val testSafeCall4: String? = J.m[""]?.let { it.toString() }
|
||||
val testIf1: String = if (true) J.s else J.s
|
||||
val testIf2: String? = if (true) J.s else J.s
|
||||
|
||||
val testIf3: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>if (true) <!TYPE_MISMATCH!>J.m[""]<!> else <!TYPE_MISMATCH!>J.m[""]<!><!>
|
||||
val testIf3: String = <!INITIALIZER_TYPE_MISMATCH!>if (true) <!TYPE_MISMATCH!>J.m[""]<!> else <!TYPE_MISMATCH!>J.m[""]<!><!>
|
||||
val testIf4: String? = if (true) J.m[""] else J.m[""]
|
||||
|
||||
val testWhen1: String = when { else -> J.s }
|
||||
val testWhen2: String? = when { else -> J.s }
|
||||
|
||||
val testWhen3: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>when { else -> <!TYPE_MISMATCH!>J.m[""]<!> }<!>
|
||||
val testWhen3: String = <!INITIALIZER_TYPE_MISMATCH!>when { else -> <!TYPE_MISMATCH!>J.m[""]<!> }<!>
|
||||
val testWhen4: String? = when { else -> J.m[""] }
|
||||
|
||||
Reference in New Issue
Block a user