Skip to content

Using the type statement to create a new int type, expr is unable to compare the new type with int. #446

@zhengycxxxx

Description

@zhengycxxxx

NewIntType==1 will be false, How to make it true.

import (
	"fmt"
	"testing"

	"github.com/antonmedv/expr"
)

type newIntType int

const (
	newIntTypeA newIntType = 1
	newIntTypeB newIntType = 2
)

func TestCalBool1(t *testing.T) {
	type XX struct {
		NewIntType newIntType
	}
	val := &XX{
		NewIntType: newIntTypeA,
	}
	s := "NewIntType==1"
	fmt.Println(CalBool(s, val))
}

func CalBool(input string, env interface{}) (bool, error) {
	output, err := cal(input, env)
	if err != nil {
		return false, err
	}

	if val, ok := output.(bool); ok {
		return val, nil
	}

	return false, err
}

func cal(input string, env interface{}) (interface{}, error) {
	return expr.Eval(input, env)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions