Skip to content
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

forward_missing_to causes segment fault when target does not exist #1826

Closed
Ragmaanir opened this issue Oct 26, 2015 · 1 comment
Closed

Comments

@Ragmaanir
Copy link

class X
  forward_missing_to x
end

X.new.test # Program exited because of a segmentation fault (11)
@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Oct 26, 2015
@asterite
Copy link
Member

This is not a bug, you get a stack overflow at runtime. Basically forward_missing_to just declares method_missing that forwards the call. So your code becomes:

class X
  macro method_missing(name, args, block)
    x.\{{name.id}}(\{{*args}}) \{{block}}
  end
end

When you invoke X.new.test, that generates:

class X
  def test
    x.test
  end
end

In that method x is a call, and we hit method_missing again, thus generating:

class X
  def x
    x.x
  end
end

and there's the stack overflow.

I guess this will be more evident once we can say "Segmentation fault" and show some of the stack trace instead of a mere segfault. I'll relate #271 to this.

@asterite asterite removed kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Oct 28, 2015
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

No branches or pull requests

3 participants