FIR DFA: reimplement type OR operation to its original semantics

#KT-43569 Fixed
This commit is contained in:
Jinseong Jeon
2020-12-01 10:56:36 -08:00
committed by Dmitriy Novozhilov
parent 16b9312695
commit cdfe1771d9
4 changed files with 26 additions and 17 deletions
@@ -140,14 +140,17 @@ abstract class LogicSystem<FLOW : Flow>(protected val context: ConeInferenceCont
private fun orForTypes(types: Collection<Set<ConeKotlinType>>): MutableSet<ConeKotlinType> {
if (types.any { it.isEmpty() }) return mutableSetOf()
val allTypes = types.flatMapTo(mutableSetOf()) { it }
val commonTypes = allTypes.toMutableSet()
types.forEach { commonTypes.retainAll(it) }
val differentTypes = types.mapNotNull { typeSet -> (typeSet - commonTypes).takeIf { it.isNotEmpty() } }
if (differentTypes.size == types.size) {
context.commonSuperTypeOrNull(differentTypes.flatten())?.let { commonTypes += it }
val intersectedTypes = types.map {
if (it.size > 1) {
context.intersectTypes(it.toList()) as ConeKotlinType
} else {
assert(it.size == 1) { "We've already checked each set of types is not empty." }
it.single()
}
}
return commonTypes
val result = mutableSetOf<ConeKotlinType>()
context.commonSuperTypeOrNull(intersectedTypes)?.let { result.add(it) }
return result
}
protected fun and(statements: Collection<TypeStatement>): MutableTypeStatement =
@@ -23,10 +23,10 @@ class Flaf {
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
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
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): kotlin/collections/set>#' type=kotlin.Unit
GET_VAR 'javaName: kotlin.String declared in <root>.Flaf.forJavaName' type=kotlin.String origin=null
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
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
<K>: kotlin.String
<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'
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]
overridden:
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?) {
if (x is Int || x is Float?) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & 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<!>
<!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?) {
if (x is Int? || x is Float) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & 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<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number? & kotlin.Comparable<kotlin.Int & kotlin.Float>? & kotlin.Any?")!>x<!>.<!INAPPLICABLE_CANDIDATE!>toByte<!>()
}
}