jashkenas / jashkenas/coffeescript

Bug: Wrong `this` in bound methods of nested classes

Open
#5,222 1 comment 5 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

While upgrading an application to CS2 we ran into the following issue in an obscure usage of nested classes.

![Screenshot 2019-07-18 at 16 33 10](https://user-images.githubusercontent.com/604618/61463194-960d3e80-a97c-11e9-9117-5df68fcc9b06.png)

As you can see, the nested bound method thought its `this` is the parent class. This seems to happen on a "parse" level, because it's replaced in the code. This lead to tricky to catch bug on our side.

Contributor guide

Open the contributing guide

Research direction

The issue names no source file or test and provides its reproduction only in a screenshot. Start by reproducing the nested-class bound-method case in the CoffeeScript compiler and inspect the parse or transformation stage where `this` is replaced. Done means the nested bound method retains its own `this`, with a regression test covering the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.