Source file src/cmd/compile/internal/types2/compilersupport.go
1 // Copyright 2021 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 // Helper functions exported for the compiler. 6 // Do not use internally. 7 8 package types2 9 10 // If t is a pointer, AsPointer returns that type, otherwise it returns nil. 11 func AsPointer(t Type) *Pointer { 12 u, _ := t.Underlying().(*Pointer) 13 return u 14 } 15 16 // If typ is a type parameter, CoreType returns the single underlying 17 // type of all types in the corresponding type constraint if it exists, or 18 // nil otherwise. If the type set contains only unrestricted and restricted 19 // channel types (with identical element types), the single underlying type 20 // is the restricted channel type if the restrictions are always the same. 21 // If typ is not a type parameter, CoreType returns the underlying type. 22 func CoreType(t Type) Type { 23 u, _ := commonUnder(t, nil) 24 return u 25 } 26 27 // RangeKeyVal returns the key and value types for a range over typ. 28 // It panics if range over typ is invalid. 29 func RangeKeyVal(typ Type) (Type, Type) { 30 key, val, _, ok := rangeKeyVal(nil, typ, nil) 31 assert(ok) 32 return key, val 33 } 34