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

// Copyright 2023 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

import 

// An Alias represents an alias type.
// Whether or not Alias types are created is controlled by the
// gotypesalias setting with the GODEBUG environment variable.
// For gotypesalias=1, alias declarations produce an Alias type.
// Otherwise, the alias information is only in the type name,
// which points directly to the actual (aliased) type.
type Alias struct {
	obj     *TypeName // corresponding declared alias object
	fromRHS Type      // RHS of type alias declaration; may be an alias
	actual  Type      // actual (aliased) type; never an alias
}

// NewAlias creates a new Alias type with the given type name and rhs.
// rhs must not be nil.
func ( *TypeName,  Type) *Alias {
	 := (*Checker)(nil).newAlias(, )
	// Ensure that alias.actual is set (#65455).
	unalias()
	return 
}

func ( *Alias) () *TypeName   { return .obj }
func ( *Alias) () Type { return unalias().Underlying() }
func ( *Alias) () string   { return TypeString(, nil) }

// Type accessors

// Unalias returns t if it is not an alias type;
// otherwise it follows t's alias chain until it
// reaches a non-alias type which is then returned.
// Consequently, the result is never an alias type.
func ( Type) Type {
	if ,  := .(*Alias);  != nil {
		return unalias()
	}
	return 
}

func unalias( *Alias) Type {
	if .actual != nil {
		return .actual
	}
	var  Type
	for  := ;  != nil; , _ = .(*Alias) {
		 = .fromRHS
	}
	if  == nil {
		panic(fmt.Sprintf("non-terminated alias %s", .obj.name))
	}
	.actual = 
	return 
}

// asNamed returns t as *Named if that is t's
// actual type. It returns nil otherwise.
func asNamed( Type) *Named {
	,  := Unalias().(*Named)
	return 
}

// newAlias creates a new Alias type with the given type name and rhs.
// rhs must not be nil.
func ( *Checker) ( *TypeName,  Type) *Alias {
	assert( != nil)
	 := &Alias{, , nil}
	if .typ == nil {
		.typ = 
	}

	// Ensure that a.actual is set at the end of type checking.
	if  != nil {
		.needsCleanup()
	}

	return 
}

func ( *Alias) () {
	Unalias()
}