确定 Golang 中函数返回的接口 {} 值的类型

确定 golang 中函数返回的接口 {} 值的类型

问题内容

我有一个从枚举返回值的函数。枚举定义如下:

type DataType int64 const ( INT DataType = iota FLOAT STRING BOOL CHAR VOID ERROR BREAK CONTINUE ) func (l *TSwiftVisitor) VisitWhileInstr(ctx *parser.WhileInstrContext) interface{} { if condExpression.ValType == BOOL { condResult := condExpression.asBool() for condResult { for _, currentInstr := range ctx.InstrList().AllInstr() { execResult := l.Visit(currentInstr) fmt.Printf("TYPE -> %Tn", execResult) // Prints exec.DataType (the type) fmt.Printf("VALUE -> %vn", execResult) // Prints 5 (the enum value) if execResult == BREAK { // This never executes fmt.Println("Es break") return VOID } else { // This executes fmt.Println("Es otra mierda") } } condResult = l.Visit(ctx.Expr()).(*Expression).asBool() } } else { return ERROR } return VOID }登录后复制