Standard library / go/types
go/types.AssignableTo()
Reports whether a value of the first type can be assigned to the second type. Type-only checks do not test constant representability. Expected stdout: 'true false\n'.
Formal Syntax & Structure
go syntaxgo
func AssignableTo(V, T Type) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| V | Type | Source or candidate type. |
| T | Type | Destination type or interface, or type to inspect. |
Return Value
bool
Reports whether a value of the first type can be assigned to the second type.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { fmt.Println(types.AssignableTo(types.Typ[types.Int], types.Typ[types.Int]), types.AssignableTo(types.Typ[types.Int], types.Typ[types.String]))}