google / google/closure-templates

Globals and "or" compiler warning

Open
#225 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
700
Forks
199
Avg merge
2d 12h
Merged PRs (30d)
26

Description

When I try to do something like
`{if GLOBAL == 'x' or GLOBAL == 'y' or GLOBAL== 'z'}`
I get a bushel (4, in fact - G==x or G==y, G==x, G==y, G==z) of compiler warnings like
```
warning: Constant operand 'GLOBAL == 'x' or GLOBAL == 'y'' used with 'or' operator. Consider simplifying
or using the ?: operator, see go/soy/reference/expressions.md#logical-operators
```

This seems like a fine use of the `or` operator to me. Yeah the GLOBAL's constant, but I don't know what it's going to be when I'm writing the template. It's my understanding that this is trying to prevent things like `{if $x or true}` or `{let $x: $y or 5}` but this is neither of those. The only way out I see to appease the compiler warning is adding some `?:` and parens in which seems...unpleasant.

Am I missing something or is this just unfortunate?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.