Source File
api_predicates.go
Belonging Package
go/types
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
// Source: ../../cmd/compile/internal/types2/api_predicates.go
// 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.
// This file implements exported type predicates.
package types
// AssertableTo reports whether a value of type V can be asserted to have type T.
//
// The behavior of AssertableTo is unspecified in three cases:
// - if T is Typ[Invalid]
// - if V is a generalized interface; i.e., an interface that may only be used
// as a type constraint in Go code
// - if T is an uninstantiated generic type
func ( *Interface, Type) bool {
// Checker.newAssertableTo suppresses errors for invalid types, so we need special
// handling here.
if !isValid(.Underlying()) {
return false
}
return (*Checker)(nil).newAssertableTo(nopos, , , nil)
}
// AssignableTo reports whether a value of type V is assignable to a variable
// of type T.
//
// The behavior of AssignableTo is unspecified if V or T is Typ[Invalid] or an
// uninstantiated generic type.
func (, Type) bool {
:= operand{mode: value, typ: }
, := .assignableTo(nil, , nil) // check not needed for non-constant x
return
}
// ConvertibleTo reports whether a value of type V is convertible to a value of
// type T.
//
// The behavior of ConvertibleTo is unspecified if V or T is Typ[Invalid] or an
// uninstantiated generic type.
func (, Type) bool {
:= operand{mode: value, typ: }
return .convertibleTo(nil, , nil) // check not needed for non-constant x
}
// Implements reports whether type V implements interface T.
//
// The behavior of Implements is unspecified if V is Typ[Invalid] or an uninstantiated
// generic type.
func ( Type, *Interface) bool {
if .Empty() {
// All types (even Typ[Invalid]) implement the empty interface.
return true
}
// Checker.implements suppresses errors for invalid types, so we need special
// handling here.
if !isValid(.Underlying()) {
return false
}
return (*Checker)(nil).implements(nopos, , , false, nil)
}
// Satisfies reports whether type V satisfies the constraint T.
//
// The behavior of Satisfies is unspecified if V is Typ[Invalid] or an uninstantiated
// generic type.
func ( Type, *Interface) bool {
return (*Checker)(nil).implements(nopos, , , true, nil)
}
// Identical reports whether x and y are identical types.
// Receivers of [Signature] types are ignored.
//
// Predicates such as [Identical], [Implements], and
// [Satisfies] assume that both operands belong to a
// consistent collection of symbols ([Object] values).
// For example, two [Named] types can be identical only if their
// [Named.Obj] methods return the same [TypeName] symbol.
// A collection of symbols is consistent if, for each logical
// package whose path is P, the creation of those symbols
// involved at most one call to [NewPackage](P, ...).
// To ensure consistency, use a single [Importer] for
// all loaded packages and their dependencies.
// For more information, see https://github.com/golang/go/issues/57497.
func (, Type) bool {
var comparer
return .identical(, , nil)
}
// IdenticalIgnoreTags reports whether x and y are identical types if tags are ignored.
// Receivers of [Signature] types are ignored.
func (, Type) bool {
var comparer
.ignoreTags = true
return .identical(, , nil)
}
The pages are generated with Golds v0.7.0-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. |