@@ -20,6 +20,9 @@ var nopos syntax.Pos
2020// debugging/development support
2121const debug = false // leave on during development
2222
23+ // position tracing for panics during type checking
24+ const tracePos = false // TODO(markfreeman): check performance implications
25+
2326// _aliasAny changes the behavior of [Scope.Lookup] for "any" in the
2427// [Universe] scope.
2528//
@@ -178,7 +181,8 @@ type Checker struct {
178181 environment
179182
180183 // debugging
181- indent int // indentation for tracing
184+ posStack []syntax.Pos // stack of source positions seen; used for panic tracing
185+ indent int // indentation for tracing
182186}
183187
184188// addDeclDep adds the dependency edge (check.decl -> to) if check.decl exists
@@ -396,6 +400,16 @@ func versionMax(a, b goVersion) goVersion {
396400 return b
397401}
398402
403+ // pushPos pushes pos onto the pos stack.
404+ func (check * Checker ) pushPos (pos syntax.Pos ) {
405+ check .posStack = append (check .posStack , pos )
406+ }
407+
408+ // popPos pops from the pos stack.
409+ func (check * Checker ) popPos () {
410+ check .posStack = check .posStack [:len (check .posStack )- 1 ]
411+ }
412+
399413// A bailout panic is used for early termination.
400414type bailout struct {}
401415
@@ -405,6 +419,7 @@ func (check *Checker) handleBailout(err *error) {
405419 // normal return or early exit
406420 * err = check .firstErr
407421 default :
422+ // TODO(markfreeman): dump posStack if available
408423 // re-panic
409424 panic (p )
410425 }
0 commit comments