Source File
under.go
Belonging Package
go/types
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.// Source: ../../cmd/compile/internal/types2/under.go// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package typesimport// If typ is a type parameter, underIs returns the result of typ.underIs(f).// Otherwise, underIs returns the result of f(typ.Underlying()).func underIs( Type, func(Type) bool) bool {return all(, func(, Type) bool {return ()})}// all reports whether f(t, u) is true for all (type/underlying type)// pairs in the typeset of t. See [typeset] for details of sequence.func all( Type, func(, Type) bool) bool {if , := Unalias().(*TypeParam); != nil {return .typeset()}return (, .Underlying())}// typeset is an iterator over the (type/underlying type) pairs of the// specific type terms of the type set implied by t.// If t is a type parameter, the implied type set is the type set of t's constraint.// In that case, if there are no specific terms, typeset calls yield with (nil, nil).// If t is not a type parameter, the implied type set consists of just t.// In any case, typeset is guaranteed to call yield at least once.func typeset( Type) iter.Seq2[Type, Type] {return func( func(, Type) bool) {_ = all(, )}}// A typeError describes a type error.type typeError struct {format_ stringargs []any}var emptyTypeError typeErrorfunc typeErrorf( string, ...any) *typeError {if == "" {return &emptyTypeError}return &typeError{, }}// format formats a type error as a string.// check may be nil.func ( *typeError) ( *Checker) string {return .sprintf(.format_, .args...)}// If t is a type parameter, cond is nil, and t's type set contains no channel types,// commonUnder returns the common underlying type of all types in t's type set if// it exists, or nil and a type error otherwise.//// If t is a type parameter, cond is nil, and there are channel types, t's type set// must only contain channel types, they must all have the same element types,// channel directions must not conflict, and commonUnder returns one of the most// restricted channels. Otherwise, the function returns nil and a type error.//// If cond != nil, each pair (t, u) of type and underlying type in t's type set// must satisfy the condition expressed by cond. If the result of cond is != nil,// commonUnder returns nil and the type error reported by cond.// Note that cond is called before any other conditions are checked; specifically// cond may be called with (nil, nil) if the type set contains no specific types.//// If t is not a type parameter, commonUnder behaves as if t was a type parameter// with the single type t in its type set.func commonUnder( Type, func(, Type) *typeError) (Type, *typeError) {var , Type // type and respective common underlying typefor , := range typeset() {if != nil {if := (, ); != nil {return nil,}}if == nil {return nil, typeErrorf("no specific type")}// If this is the first type we're seeing, we're done.if == nil {, = ,continue}// If we've seen a channel before, and we have a channel now, they must be compatible.if , := .(*Chan); != nil {if , := .(*Chan); != nil {if !Identical(.elem, .elem) {return nil, typeErrorf("channels %s and %s have different element types", , )}// If we have different channel directions, keep the restricted one// and complain if they conflict.switch {case .dir == .dir:// nothing to docase .dir == SendRecv:, = , // switch to restricted channelcase .dir != SendRecv:return nil, typeErrorf("channels %s and %s have conflicting directions", , )}continue}}// Otherwise, the current type must have the same underlying type as all previous types.if !Identical(, ) {return nil, typeErrorf("%s and %s have different underlying types", , )}}return , nil}
![]() |
The pages are generated with Golds v0.8.3-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |