Source file src/go/types/target.go
1 // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT. 2 // Source: ../../cmd/compile/internal/types2/target.go 3 4 // Copyright 2026 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 // This file implements target types for expressions in assignment contexts. 9 10 package types 11 12 // target represents the target type in an assignment context. 13 type target struct { 14 typ Type 15 // TODO(gri) desc is only used in Checker.funcInst - do we need it? 16 // (setting/computing desc may be expensive for not being used) 17 // Also, if we keep it, review consistency of description. 18 desc string 19 hint bool // if set, the target may be used as untyped composite literal hint before Go 1.28 20 } 21 22 // newTarget creates a new target for the given type and description. 23 // The result is nil if typ is nil. 24 func newTarget(typ Type, desc string) *target { 25 if typ != nil { 26 return &target{typ, desc, false} 27 } 28 return nil 29 } 30 31 // newHint is like newTarget but it marks the result as a hint. 32 func newHint(typ Type, desc string) *target { 33 if typ != nil { 34 return &target{typ, desc, true} 35 } 36 return nil 37 } 38 39 // sig returns the target type T if it is a signature (the result may be its Named or Alias type, if any). 40 // The result is nil if T is nil or T's type set has no common signature type. 41 func (T *target) sig() Type { 42 if T != nil { 43 if u, _ := commonUnder(T.typ, nil); u != nil { 44 if _, ok := u.(*Signature); ok { 45 return T.typ 46 } 47 } 48 } 49 return nil 50 } 51 52 // String returns a string representation of T, for debugging. 53 func (T *target) String() string { 54 if T != nil { 55 return sprintf(nil, nil, true, "target{%s, %q}", T.typ, T.desc) 56 } 57 return "no target" 58 } 59