coffeescript icon indicating copy to clipboard operation
coffeescript copied to clipboard

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

Open Inve1951 opened this issue 5 years ago • 3 comments

Input Code

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

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

Expected Behavior

Same as:

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

Inve1951 avatar Sep 23 '18 22:09 Inve1951

Looks like my use case was bad. Above code should still compile tho: #try

Inve1951 avatar Sep 24 '18 12:09 Inve1951

See #4754, as well as #4869

vendethiel avatar Sep 24 '18 12:09 vendethiel

Mhm.

Like you suspected there https://github.com/jashkenas/coffeescript/pull/4754#issuecomment-

This won't catch code like class extends A then constructor: (@a) -> super((=> @a)()), but I'm not sure if that's supposedly valid. (or if super(=> @a) in general is valid).

that's valid code (flow) in js.

Or rather in my example, passing a function to super which takes @param. However you must not call it before super returns.

Inve1951 avatar Sep 24 '18 12:09 Inve1951