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

Interpreter segfaults trying to access instance variable #13163

Open
ysbaddaden opened this issue Mar 8, 2023 · 0 comments
Open

Interpreter segfaults trying to access instance variable #13163

ysbaddaden opened this issue Mar 8, 2023 · 0 comments

Comments

@ysbaddaden
Copy link
Contributor

While trying out the interpreter I ran into a segfault that only happens with when interpreted. This is the furthest that I could reduce it.

abstract struct View
  @__io__ = uninitialized IO # also segfaults with IO|Nil

  def render(io : IO, &block) : Nil
    @__io__ = io
    template(&block)
  end

  def render(view : View, &block) : Nil
    view.render(@__io__, &block)
  end

  def will_segfault(&) : Nil
    p @__io__ # NOTE: segfault: invalid reference to @__io__
  end
end

struct Component < View
  def template(&)
    will_segfault {}
  end
end

struct Example < View
  def template(&)
    render(Component.new) do
      render(Component.new) {} # NOTE: removing this line prevents the segfault
    end
  end
end

Example.new.render(IO::Memory.new) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants