bpftrace icon indicating copy to clipboard operation
bpftrace copied to clipboard

Allow logical operators on more types

Open fbs opened this issue 4 years ago • 3 comments

Logical operators currently only work on integer types, using any other type fails with:

ERROR: Type mismatch for '&&': comparing 'int64' with 'string[64]'

I think we can define a truthy/false value for (almost ) all types, like an empty string could be false and non empty evaluating to true.

One case to keep in mind is maps, say we have

BEGIN { @[1]="" }

i:s:1 /@[1]/ { print(xxx) }

Do we use the map value (and empty string evaluating to false) or the fact that the map has a value. We need to stay compatible here.

fbs avatar Mar 11 '21 17:03 fbs

Relates /expands #1579

fbs avatar Mar 11 '21 17:03 fbs

How would truthiness work for structs?

danobi avatar Mar 12 '21 03:03 danobi

@danobi don't think we'd be able to have it defined for structs. For pointer types yes (null -> falsey), but not structs.

ghost avatar Mar 16 '21 17:03 ghost