pgraph, lang: ast: Fix failing tests due to non-deterministic topo sort

This causes inconsistent type unification when running our tests. It's a
bad user experience too.
This commit is contained in:
James Shubin
2024-07-01 18:34:24 -04:00
parent 14577a0c46
commit f2976deb02
5 changed files with 66 additions and 5 deletions

View File

@@ -3829,8 +3829,10 @@ func (obj *StmtProg) SetScope(scope *interfaces.Scope) error {
orderingGraphSingleton = false
}
//nodeOrder, err := orderingGraphFiltered.TopologicalSort()
nodeOrder, err := orderingGraph.TopologicalSort()
// If we don't do this deterministically the type unification errors can
// flip from `type error: Int != Str` to `type error: Str != Int` etc...
nodeOrder, err := orderingGraph.DeterministicTopologicalSort() // sorted!
if err != nil {
// TODO: print the cycle in a prettier way (with names?)
if obj.data.Debug {