jashkenas / jashkenas/coffeescript
Bug: Chained comparison doesn't work with `in` binary operator
- Dominant language
- CoffeeScript
- Stars
- 16.6k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
`in` is a relational operator and should work with chained comparisons.
### Input Code
```coffee
a in b in d
```
### Expected Behavior
```
var ref,
indexOf = [].indexOf;
indexOf.call(b, a) >= 0 && indexOf.call(d, b) >= 0;
```
### Current Behavior
```javascript
var ref,
indexOf = [].indexOf;
ref = indexOf.call(b, a) >= 0, indexOf.call(d, ref) >= 0;
```
### Python Behavior
```python
daniel@DESKTOP-HATA8GU:~/apps/civet$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1
>>> b = [1]
>>> a in b
True
>>> c = [b]
>>> b in c
True
>>> a in b in c
True
>>>
```
* CoffeeScript version: 2.7.0
@GeoffreyBooth Feel encouraged to bundle up these "breaking changes" bug reports into a Coffee3 tag/milestone... a man can dream 🌟
Contributor guide
Research direction
Start by locating the parser and code-generation handling for relational operators and chained comparisons. Add a regression case for `a in b in d`, then verify that the generated JavaScript preserves both membership checks without assigning the first result to a temporary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript, javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100