Source file src/cmd/compile/internal/types2/target.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 // This file implements target types for expressions in assignment contexts. 6 7 package types2 8 9 // target represents the target type in an assignment context. 10 type target struct { 11 typ Type 12 // TODO(gri) desc is only used in Checker.funcInst - do we need it? 13 // (setting/computing desc may be expensive for not being used) 14 // Also, if we keep it, review consistency of description. 15 desc string 16 hint bool // if set, the target may be used as untyped composite literal hint before Go 1.28 17 } 18 19 // newTarget creates a new target for the given type and description. 20 // The result is nil if typ is nil. 21 func newTarget(typ Type, desc string) *target { 22 if typ != nil { 23 return &target{typ, desc, false} 24 } 25 return nil 26 } 27 28 // newHint is like newTarget but it marks the result as a hint. 29 func newHint(typ Type, desc string) *target { 30 if typ != nil { 31 return &target{typ, desc, true} 32 } 33 return nil 34 } 35 36 // sig returns the target type T if it is a signature (the result may be its Named or Alias type, if any). 37 // The result is nil if T is nil or T's type set has no common signature type. 38 func (T *target) sig() Type { 39 if T != nil { 40 if u, _ := commonUnder(T.typ, nil); u != nil { 41 if _, ok := u.(*Signature); ok { 42 return T.typ 43 } 44 } 45 } 46 return nil 47 } 48 49 // String returns a string representation of T, for debugging. 50 func (T *target) String() string { 51 if T != nil { 52 return sprintf(nil, true, "target{%s, %q}", T.typ, T.desc) 53 } 54 return "no target" 55 } 56