From a50765393ddf7a22a2957e4c5cb705b9b7567b29 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 9 Mar 2025 01:49:37 -0500 Subject: [PATCH] lang: ast: Catch ordering errors --- lang/ast/structs.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lang/ast/structs.go b/lang/ast/structs.go index 6b97d1a6..e7abaf64 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -5017,7 +5017,6 @@ func (obj *StmtProg) SetScope(scope *interfaces.Scope) error { // 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 { @@ -5026,6 +5025,12 @@ func (obj *StmtProg) SetScope(scope *interfaces.Scope) error { } return errwrap.Wrapf(err, "recursive reference while setting scope") } + if obj.data.Debug { // XXX: catch ordering errors in the logs + obj.data.Logf("nodeOrder:") + for i, x := range nodeOrder { + obj.data.Logf("nodeOrder[%d]: %+v", i, x) + } + } // XXX: implement ValidTopoSortOrder! //topoSanity := (RequireTopologicalOrdering || TopologicalOrderingWarning)