package types
import (
)
func ( bool) {
if ! {
panic("assertion failed")
}
}
func () {
panic("unreachable")
}
func ( *Checker) ( *Package) string {
if != .pkg {
if .pkgPathMap == nil {
.pkgPathMap = make(map[string]map[string]bool)
.seenPkgMap = make(map[*Package]bool)
.markImports(.pkg)
}
if len(.pkgPathMap[.name]) > 1 {
return strconv.Quote(.path)
}
return .name
}
return ""
}
func ( *Checker) ( *Package) {
if .seenPkgMap[] {
return
}
.seenPkgMap[] = true
, := .pkgPathMap[.name]
if ! {
= make(map[string]bool)
.pkgPathMap[.name] =
}
[.path] = true
for , := range .imports {
.()
}
}
func ( *Checker) ( string, ...any) string {
var *token.FileSet
var Qualifier
if != nil {
= .fset
= .qualifier
}
return sprintf(, , false, , ...)
}
func ( *token.FileSet, Qualifier, bool, string, ...any) string {
for , := range {
switch a := .(type) {
case nil:
= "<nil>"
case operand:
panic("got operand instead of *operand")
case *operand:
= operandString(, )
case token.Pos:
if != nil {
= .Position().String()
}
case ast.Expr:
= ExprString()
case []ast.Expr:
var bytes.Buffer
.WriteByte('[')
writeExprList(&, )
.WriteByte(']')
= .String()
case Object:
= ObjectString(, )
case Type:
= typeString(, , )
case []Type:
var bytes.Buffer
.WriteByte('[')
for , := range {
if > 0 {
.WriteString(", ")
}
.WriteString(typeString(, , ))
}
.WriteByte(']')
= .String()
case []*TypeParam:
var bytes.Buffer
.WriteByte('[')
for , := range {
if > 0 {
.WriteString(", ")
}
.WriteString(typeString(, , ))
}
.WriteByte(']')
= .String()
}
[] =
}
return fmt.Sprintf(, ...)
}
func ( *Checker) ( token.Pos, string, ...any) {
fmt.Printf("%s:\t%s%s\n",
.fset.Position(),
strings.Repeat(". ", .indent),
sprintf(.fset, .qualifier, true, , ...),
)
}
func ( *Checker) ( string, ...any) {
fmt.Println(sprintf(.fset, .qualifier, true, , ...))
}
func ( *Checker) ( error) {
if == nil {
return
}
var Error
:= errors.As(, &)
:= && (strings.Index(.Msg, "invalid operand") > 0 || strings.Index(.Msg, "invalid type") > 0)
if .firstErr != nil && {
return
}
if {
.Msg = stripAnnotations(.Msg)
if .errpos != nil {
:= spanOf(.errpos)
.Pos = .pos
.go116start = .start
.go116end = .end
}
=
}
if .firstErr == nil {
.firstErr =
}
if trace {
:= .Pos
:= .Msg
if ! {
= .Error()
= token.NoPos
}
.trace(, "ERROR: %s", )
}
:= .conf.Error
if == nil {
panic(bailout{})
}
()
}
func ( *Checker) ( positioner, errorCode, bool, string) error {
:= spanOf()
return Error{
Fset: .fset,
Pos: .pos,
Msg: ,
Soft: ,
go116code: ,
go116start: .start,
go116end: .end,
}
}
func ( *Checker) ( positioner, errorCode, bool, string, ...any) error {
:= .sprintf(, ...)
return .newError(, , , )
}
func ( *Checker) ( positioner, errorCode, string) {
.err(.newError(, , false, ))
}
func ( *Checker) ( positioner, errorCode, string, ...any) {
.error(, , .sprintf(, ...))
}
func ( *Checker) ( positioner, errorCode, string, ...any) {
.err(.newErrorf(, , true, , ...))
}
func ( *Checker) ( positioner, string, ...any) {
.errorf(, 0, "invalid AST: "+, ...)
}
func ( *Checker) ( positioner, errorCode, string, ...any) {
.errorf(, , "invalid argument: "+, ...)
}
func ( *Checker) ( positioner, errorCode, string, ...any) {
.errorf(, , "invalid operation: "+, ...)
}
type positioner interface {
Pos() token.Pos
}
type posSpan struct {
start, pos, end token.Pos
}
func ( posSpan) () token.Pos {
return .pos
}
func ( ast.Node, token.Pos) posSpan {
, := .Pos(), .End()
if debug {
assert( <= && < )
}
return posSpan{, , }
}
type atPos token.Pos
func ( atPos) () token.Pos {
return token.Pos()
}
func ( positioner) posSpan {
switch x := .(type) {
case nil:
panic("nil positioner")
case posSpan:
return
case ast.Node:
:= .Pos()
return posSpan{, , .End()}
case *operand:
if .expr != nil {
:= .Pos()
return posSpan{, , .expr.End()}
}
return posSpan{token.NoPos, token.NoPos, token.NoPos}
default:
:= .Pos()
return posSpan{, , }
}
}
func ( string) string {
var strings.Builder
for , := range {
if < '₀' || '₀'+10 <= {
.WriteRune()
}
}
if .Len() < len() {
return .String()
}
return
}