Skip to content

Bugfix 1183 #2252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 24, 2012
Merged

Bugfix 1183 #2252

merged 5 commits into from
Apr 24, 2012

Conversation

maxtaco
Copy link
Contributor

@maxtaco maxtaco commented Apr 11, 2012

This should fix #1183. Fixing the compiler error revealed a couple of bugs in the runtime (_this versus this and also passing this through closures). There might be other runtime cases that I missed, since the two cases I tried (wraps and fat-arrows) needed to be handled separately.

@@ -30,6 +30,11 @@ exports.Scope = class Scope
else
@positions[name] = @variables.push({name, type}) - 1

getMethodRecurse: ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a comment above this line with a small description or some usage intentions?

@michaelficarra
Copy link
Collaborator

Nice. How do you feel about taking care of the related #1392?

@maxtaco
Copy link
Contributor Author

maxtaco commented Apr 12, 2012

I took a look at #1392, I'll give it a stab if I can find some time.

@jashkenas jashkenas merged commit b03bea1 into jashkenas:master Apr 24, 2012
@@ -1924,7 +1929,8 @@ Closure =

literalThis: (node) ->
(node instanceof Literal and node.value is 'this' and not node.asKey) or
(node instanceof Code and node.bound)
(node instanceof Code and node.bound) or
(node instanceof Call and node.isSuper)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxtaco -- @michaelficarra, as part of my refactoring of this commit in 34be878, I removed this change. No tests failed after I did so. Was this needed for some behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let me page this back in.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Either this was gratuitous or the tests weren't comprehensive. Either way, not good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember thinking, "man, this is going to be ugly to write a regtest for." Still playing around with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I was wrong about the above, it's a pretty simple case. Here is but one instance when the current code gets it wrong:

class A
  constructor : ->
     @i = 10
  foo :  ->
     console.log "A:foo #{@i}"

class B extends A
  foo :  ->
    x = switch x
      when 'a'
        something()
      else
        super()

b = new B()
b.foo()

With my fix, this snippet works and prints "A:foo 10". The new proposed fix prints "A:foo undefined" What's going on is this. Sometimes the code in the method that calls super will be compiled into a wrapped closure. If that's so, it has to trigger the check that calls the wrapper closure with this from the parent. With the new proposed fix, the closure is called with no arguments.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable, although that particular test case is a wee bit golfed ;)

Want to send the patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously, I'm in a mad rush. Sure, I'll send something off later tonight. What's the preferred way to force a node.compileClosure on line 47 in nodes.coffee? That's what my ugly switch was trying to do.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preferred way to force it is to make the particular node's isStatement check return true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

super and wrapped statement
3 participants