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

Fix parse error for delegate statements with dynamic arguments #114

Merged
merged 4 commits into from
May 30, 2023

Conversation

latortuga
Copy link
Contributor

@latortuga latortuga commented May 30, 2023

I updated to 1.0 today because I saw the announcement in Ruby Weekly last week. I am now getting a NoMethodError where previously there was no error when parsing (on v.0.9.1):

NoMethodError parsing `myfile.rb': undefined method `first' for nil:NilClass

To be clear, I can still use it but this particular construction seems to throw the parser.

I've made a minimal test case that recreates the behavior.

class C
  def object = Object.new

  # these all work
  delegate :thing, to: :object
  delegate :thing=, to: :object
  %i(other).each do |k|
    delegate k, to: :object
    delegate :"#{k}", to: :object
  end

  # does not work!
  %(foo).each do |k|
    delegate k, :"#{k}=", to: :object
  end
end

@latortuga
Copy link
Contributor Author

I just made the test because I am not sure how to fix this at this point and wanted y'all to know it was happening. I'm not entirely sure if this can be fixed because it seems to be regarding an argument to delegate that is determined dynamically but even if we can't make it function I figured it should not throw an error.

@latortuga
Copy link
Contributor Author

(btw @mislav thank you for will_paginate ❤️ )

@mislav mislav changed the title Add test demonstrating parsing error in v1.0 Fix parse error for delegate statements with dynamic arguments May 30, 2023
@mislav mislav merged commit aac79d8 into tmm1:master May 30, 2023
@mislav
Copy link
Collaborator

mislav commented May 30, 2023

Thank you for reporting!

The ruby 2.2 CI failure is not related to this change: ruby/setup-ruby#496

@latortuga latortuga deleted the parsing-errors branch May 30, 2023 18:53
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.

2 participants