jashkenas / jashkenas/coffeescript

Bug: Wrong positive for `@params in derived class constructors`

Open
#5,111 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

### [Input Code](https://coffeescript.org/v2/#try:class%20A%20extends%20B%0A%20%20constructor%3A%20-%3E%0A%20%20%20%20super%20(%40a)%20%3D%3E%0A)
```coffee
class A extends B
constructor: ->
super (@a) =>

# or
class A extends B
constructor: ->
super (a) =>
@a = a
```

### [Expected Behavior](https://coffeescript.org/v2/#try:class%20A%20extends%20B%0A%20%20constructor%3A%20-%3E%0A%20%20%20%20super%20(a)%20%3D%3E%0A%20%20%20%20%20%20this.a%20%3D%20a%0A)
Same as:
```coffee
class A extends B
constructor: ->
super (a) =>
this.a = a
```

### Current Behavior
```
[stdin]:3:12: error: Can't call super with @params in derived class constructors
super (@a) =>
^^

[stdin]:4:7: error: Can't call super with @params in derived class constructors
@a = a
^^
```

### Context
Use case is promise extension.

### Environment

* CoffeeScript v2.3.2
* Node.js v7.10 custom build

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied CoffeeScript input with CoffeeScript v2.3.2 and trace the compiler path that diagnoses @params in derived constructors. Compare it with the expected equivalent using a local variable; done means the valid forms compile without this error while genuinely invalid @params uses remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.