expr icon indicating copy to clipboard operation
expr copied to clipboard

Cannot use T as type int in array

Open loggerhead opened this issue 7 months ago • 2 comments

I have read the document several times but still can't understand where the usage issues are. Could you please help take a look?

https://go.dev/play/p/LwYtRm2NuXM

Image

loggerhead avatar May 29 '25 13:05 loggerhead

Looks like #632

seruman avatar May 30 '25 09:05 seruman

Yes, this is by design.

type Platform int

In internal golang representation, Platform is different from the int. Although Expr does automative type conversions for ints, in this case you will need to case to int explisitly:

int(platform) in [1, 2]

Explanation about why Golang behaves this way: https://github.com/expr-lang/expr/issues/632#issuecomment-2069038213

antonmedv avatar May 30 '25 12:05 antonmedv