FIR CFA: ensure on API level that graphs have enter & exit

What's going on with script graphs?..
This commit is contained in:
pyos
2022-12-10 20:59:26 +01:00
committed by Dmitriy Novozhilov
parent e710edbd77
commit 3887c80816
8 changed files with 104 additions and 193 deletions
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
import org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.CFGNode
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.ControlFlowGraph
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.GraphEnterNodeMarker
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.GraphExitNodeMarker
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
import org.jetbrains.kotlin.test.Assertions
@@ -19,7 +21,8 @@ class FirCfgConsistencyChecker(private val assertions: Assertions) : FirVisitorV
override fun visitControlFlowGraphReference(controlFlowGraphReference: FirControlFlowGraphReference) {
val graph = (controlFlowGraphReference as? FirControlFlowGraphReferenceImpl)?.controlFlowGraph ?: return
assertions.assertEquals(ControlFlowGraph.State.Completed, graph.state)
assertions.assertEquals(graph.nodes.single { it is GraphEnterNodeMarker }, graph.enterNode)
assertions.assertEquals(graph.nodes.single { it is GraphExitNodeMarker }, graph.exitNode)
checkConsistency(graph)
checkOrder(graph)
}