// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.

// 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 types

// under returns the true expanded underlying type.
// If it doesn't exist, the result is Typ[Invalid].
// under must only be called when a type is known
// to be fully set up.
func under( Type) Type {
	if ,  := .(*Named);  != nil {
		return .under()
	}
	return .Underlying()
}

// If t is not a type parameter, coreType returns the underlying type.
// If t is a type parameter, coreType returns the single underlying
// type of all types in its type set if it exists, or nil otherwise. If the
// type set contains only unrestricted and restricted channel types (with
// identical element types), the single underlying type is the restricted
// channel type if the restrictions are always the same, or nil otherwise.
func coreType( Type) Type {
	,  := .(*TypeParam)
	if  == nil {
		return under()
	}

	var  Type
	if .underIs(func( Type) bool {
		if  == nil {
			return false
		}
		if  != nil {
			 = match(, )
			if  == nil {
				return false
			}
		}
		// su == nil || match(su, u) != nil
		 = 
		return true
	}) {
		return 
	}
	return nil
}

// coreString is like coreType but also considers []byte
// and strings as identical. In this case, if successful and we saw
// a string, the result is of type (possibly untyped) string.
func coreString( Type) Type {
	,  := .(*TypeParam)
	if  == nil {
		return under() // string or untyped string
	}

	var  Type
	 := false
	if .underIs(func( Type) bool {
		if  == nil {
			return false
		}
		if isString() {
			 = NewSlice(universeByte)
			 = true
		}
		if  != nil {
			 = match(, )
			if  == nil {
				return false
			}
		}
		// su == nil || match(su, u) != nil
		 = 
		return true
	}) {
		if  {
			return Typ[String]
		}
		return 
	}
	return nil
}

// If x and y are identical, match returns x.
// If x and y are identical channels but for their direction
// and one of them is unrestricted, match returns the channel
// with the restricted direction.
// In all other cases, match returns nil.
func match(,  Type) Type {
	// Common case: we don't have channels.
	if Identical(, ) {
		return 
	}

	// We may have channels that differ in direction only.
	if ,  := .(*Chan);  != nil {
		if ,  := .(*Chan);  != nil && Identical(.elem, .elem) {
			// We have channels that differ in direction only.
			// If there's an unrestricted channel, select the restricted one.
			switch {
			case .dir == SendRecv:
				return 
			case .dir == SendRecv:
				return 
			}
		}
	}

	// types are different
	return nil
}