Source file src/cmd/compile/internal/midway/check.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package midway
     6  
     7  import (
     8  	"cmd/compile/internal/base"
     9  	"cmd/compile/internal/syntax"
    10  )
    11  
    12  // CheckPositions checks that all nodes in the files have known positions.
    13  // This converts lack-of-Pos into an early fatal error instead of a later
    14  // weird downstream error (e.g., in the linker, in debugging information).
    15  func CheckPositions(files []*syntax.File, phase string) {
    16  	for _, file := range files {
    17  		syntax.Inspect(file, func(n syntax.Node) bool {
    18  			if n == nil {
    19  				return true
    20  			}
    21  			if !n.Pos().IsKnown() {
    22  				base.Fatalf("Phase %s, Node without known position: %T\n", phase, n)
    23  			}
    24  			return true
    25  		})
    26  	}
    27  }
    28  

View as plain text