FIR DFA: reimplement type OR operation to its original semantics
#KT-43569 Fixed
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
16b9312695
commit
cdfe1771d9
@@ -140,14 +140,17 @@ abstract class LogicSystem<FLOW : Flow>(protected val context: ConeInferenceCont
|
|||||||
|
|
||||||
private fun orForTypes(types: Collection<Set<ConeKotlinType>>): MutableSet<ConeKotlinType> {
|
private fun orForTypes(types: Collection<Set<ConeKotlinType>>): MutableSet<ConeKotlinType> {
|
||||||
if (types.any { it.isEmpty() }) return mutableSetOf()
|
if (types.any { it.isEmpty() }) return mutableSetOf()
|
||||||
val allTypes = types.flatMapTo(mutableSetOf()) { it }
|
val intersectedTypes = types.map {
|
||||||
val commonTypes = allTypes.toMutableSet()
|
if (it.size > 1) {
|
||||||
types.forEach { commonTypes.retainAll(it) }
|
context.intersectTypes(it.toList()) as ConeKotlinType
|
||||||
val differentTypes = types.mapNotNull { typeSet -> (typeSet - commonTypes).takeIf { it.isNotEmpty() } }
|
} else {
|
||||||
if (differentTypes.size == types.size) {
|
assert(it.size == 1) { "We've already checked each set of types is not empty." }
|
||||||
context.commonSuperTypeOrNull(differentTypes.flatten())?.let { commonTypes += it }
|
it.single()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return commonTypes
|
val result = mutableSetOf<ConeKotlinType>()
|
||||||
|
context.commonSuperTypeOrNull(intersectedTypes)?.let { result.add(it) }
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun and(statements: Collection<TypeStatement>): MutableTypeStatement =
|
protected fun and(statements: Collection<TypeStatement>): MutableTypeStatement =
|
||||||
|
|||||||
+2
-2
@@ -23,10 +23,10 @@ class Flaf {
|
|||||||
result = Flaf(javaName = javaName)
|
result = Flaf(javaName = javaName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error("") /* ErrorCallExpression */javaName; result;
|
<this>.<get-INSTANCES>().set<String, Flaf>(key = javaName, value = result /*as Flaf */)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result /*as Flaf */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,17 @@ FILE fqName:<root> fileName:/inapplicableCollectionSet.kt
|
|||||||
SET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=kotlin.Unit origin=EQ
|
SET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=kotlin.Unit origin=EQ
|
||||||
CONSTRUCTOR_CALL 'public constructor <init> (javaName: kotlin.String) [primary] declared in <root>.Flaf' type=<root>.Flaf origin=null
|
CONSTRUCTOR_CALL 'public constructor <init> (javaName: kotlin.String) [primary] declared in <root>.Flaf' type=<root>.Flaf origin=null
|
||||||
javaName: GET_VAR 'javaName: kotlin.String declared in <root>.Flaf.forJavaName' type=kotlin.String origin=null
|
javaName: GET_VAR 'javaName: kotlin.String declared in <root>.Flaf.forJavaName' type=kotlin.String origin=null
|
||||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): kotlin/collections/set>#' type=kotlin.Unit
|
CALL 'public final fun set <K, V> (key: K of kotlin.collections.set, value: V of kotlin.collections.set): kotlin.Unit [inline,operator] declared in kotlin.collections' type=kotlin.Unit origin=null
|
||||||
GET_VAR 'javaName: kotlin.String declared in <root>.Flaf.forJavaName' type=kotlin.String origin=null
|
<K>: kotlin.String
|
||||||
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
|
<V>: <root>.Flaf
|
||||||
|
$receiver: CALL 'private final fun <get-INSTANCES> (): kotlin.collections.MutableMap<kotlin.String, <root>.Flaf> declared in <root>.Flaf' type=kotlin.collections.MutableMap<kotlin.String, <root>.Flaf> origin=GET_PROPERTY
|
||||||
|
$this: GET_VAR '<this>: <root>.Flaf declared in <root>.Flaf.forJavaName' type=<root>.Flaf origin=null
|
||||||
|
key: GET_VAR 'javaName: kotlin.String declared in <root>.Flaf.forJavaName' type=kotlin.String origin=null
|
||||||
|
value: TYPE_OP type=<root>.Flaf origin=IMPLICIT_CAST typeOperand=<root>.Flaf
|
||||||
|
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
|
||||||
RETURN type=kotlin.Nothing from='public final fun forJavaName (javaName: kotlin.String): <root>.Flaf declared in <root>.Flaf'
|
RETURN type=kotlin.Nothing from='public final fun forJavaName (javaName: kotlin.String): <root>.Flaf declared in <root>.Flaf'
|
||||||
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
|
TYPE_OP type=<root>.Flaf origin=IMPLICIT_CAST typeOperand=<root>.Flaf
|
||||||
|
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
|
||||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||||
overridden:
|
overridden:
|
||||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ fun case_1(x: Any) {
|
|||||||
*/
|
*/
|
||||||
fun case_2(x: Any?) {
|
fun case_2(x: Any?) {
|
||||||
if (x is Int || x is Float?) {
|
if (x is Int || x is Float?) {
|
||||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any?")!>x<!>
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number? & kotlin.Comparable<kotlin.Int & kotlin.Float>? & kotlin.Any?")!>x<!>
|
||||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any?")!>x<!>.<!UNRESOLVED_REFERENCE!>toByte<!>()
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number? & kotlin.Comparable<kotlin.Int & kotlin.Float>? & kotlin.Any?")!>x<!>.<!INAPPLICABLE_CANDIDATE!>toByte<!>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,8 +30,8 @@ fun case_2(x: Any?) {
|
|||||||
*/
|
*/
|
||||||
fun case_3(x: Any?) {
|
fun case_3(x: Any?) {
|
||||||
if (x is Int? || x is Float) {
|
if (x is Int? || x is Float) {
|
||||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any?")!>x<!>
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number? & kotlin.Comparable<kotlin.Int & kotlin.Float>? & kotlin.Any?")!>x<!>
|
||||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any?")!>x<!>.<!UNRESOLVED_REFERENCE!>toByte<!>()
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number? & kotlin.Comparable<kotlin.Int & kotlin.Float>? & kotlin.Any?")!>x<!>.<!INAPPLICABLE_CANDIDATE!>toByte<!>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user