FIR DFA: workaround KT-46826
This commit is contained in:
committed by
TeamCityServer
parent
0ecc752813
commit
b78b50e1f8
+4
-14
@@ -134,7 +134,7 @@ abstract class PersistentLogicSystem(context: ConeInferenceContext) : LogicSyste
|
|||||||
|
|
||||||
val variables = flows.flatMap { it.approvedTypeStatements.keys }.toSet()
|
val variables = flows.flatMap { it.approvedTypeStatements.keys }.toSet()
|
||||||
for (variable in variables) {
|
for (variable in variables) {
|
||||||
val info = mergeOperation(flows.map { it.getApprovedTypeStatements(variable, commonFlow) }) ?: continue
|
val info = mergeOperation(flows.map { it.getApprovedTypeStatements(variable) }) ?: continue
|
||||||
removeTypeStatementsAboutVariable(commonFlow, variable)
|
removeTypeStatementsAboutVariable(commonFlow, variable)
|
||||||
val thereWereReassignments = variable.hasDifferentReassignments(flows)
|
val thereWereReassignments = variable.hasDifferentReassignments(flows)
|
||||||
if (thereWereReassignments) {
|
if (thereWereReassignments) {
|
||||||
@@ -210,23 +210,13 @@ abstract class PersistentLogicSystem(context: ConeInferenceContext) : LogicSyste
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(DfaInternals::class)
|
@OptIn(DfaInternals::class)
|
||||||
private fun PersistentFlow.getApprovedTypeStatements(variable: RealVariable, parentFlow: PersistentFlow): MutableTypeStatement {
|
private fun PersistentFlow.getApprovedTypeStatements(variable: RealVariable): MutableTypeStatement {
|
||||||
var flow = this
|
var flow = this
|
||||||
val result = MutableTypeStatement(variable)
|
val result = MutableTypeStatement(variable)
|
||||||
val variableUnderAlias = directAliasMap[variable]
|
val variableUnderAlias = directAliasMap[variable]
|
||||||
if (variableUnderAlias == null) {
|
if (variableUnderAlias == null) {
|
||||||
// get approved type statement even though the starting flow == parent flow
|
flow.approvedTypeStatements[variable]?.let {
|
||||||
if (flow == parentFlow) {
|
result += it
|
||||||
flow.approvedTypeStatements[variable]?.let {
|
|
||||||
result += it
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
while (flow != parentFlow) {
|
|
||||||
flow.approvedTypeStatements[variable]?.let {
|
|
||||||
result += it
|
|
||||||
}
|
|
||||||
flow = flow.previousFlow!!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.exactType.addIfNotNull(variableUnderAlias.originalType)
|
result.exactType.addIfNotNull(variableUnderAlias.originalType)
|
||||||
|
|||||||
+1
-1
@@ -4,6 +4,6 @@ fun foo(y: String?) {
|
|||||||
var x: String? = ""
|
var x: String? = ""
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
y?.let { x = null }
|
y?.let { x = null }
|
||||||
x.length // Smart cast is not possible
|
x<!UNSAFE_CALL!>.<!>length // Smart cast is not possible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user