coffeescript
coffeescript copied to clipboard
Bug: Wrong positive for `@params in derived class constructors`
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
Looks like my use case was bad. Above code should still compile tho: #try
See #4754, as well as #4869
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 ifsuper(=> @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.