cuelang.org/go@v0.10.1/internal/golangorgx/tools/aliases/aliases.go (about)

     1  // Copyright 2024 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 aliases
     6  
     7  import (
     8  	"go/token"
     9  	"go/types"
    10  )
    11  
    12  // Package aliases defines backward compatible shims
    13  // for the types.Alias type representation added in 1.22.
    14  // This defines placeholders for x/tools until 1.26.
    15  
    16  // NewAlias creates a new TypeName in Package pkg that
    17  // is an alias for the type rhs.
    18  //
    19  // When GoVersion>=1.22 and GODEBUG=gotypesalias=1,
    20  // the Type() of the return value is a *types.Alias.
    21  func NewAlias(pos token.Pos, pkg *types.Package, name string, rhs types.Type) *types.TypeName {
    22  	if enabled() {
    23  		tname := types.NewTypeName(pos, pkg, name, nil)
    24  		newAlias(tname, rhs)
    25  		return tname
    26  	}
    27  	return types.NewTypeName(pos, pkg, name, rhs)
    28  }