Standard library / go/types
go/types.ConvertibleTo()
Reports whether a conversion between two types is permitted. Expected stdout: 'true false\n'.
Formal Syntax & Structure
go syntaxgo
func ConvertibleTo(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 conversion between two types is permitted.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { fmt.Println(types.ConvertibleTo(types.Typ[types.Int], types.Typ[types.Int64]), types.ConvertibleTo(types.Typ[types.String], types.Typ[types.Bool]))}