ffi-clang icon indicating copy to clipboard operation
ffi-clang copied to clipboard

Undefined method `visit_children' for an instance of FFI::Clang::Cursor (NoMethodError)

Open PromanSEW opened this issue 1 year ago • 7 comments

How to fix this error? OS: macOS Sonoma 14.6.1 Apple clang version: 15.0.0 (clang-1500.3.9.4) Ruby: 3.3.5 Gems: ffi (1.17.0 arm64-darwin) ffi-clang (0.10.0)

I try to run bro-gen.rb from https://github.com/dkimitsa/robovm-bro-gen But got this error:

/Users/roman/Downloads/bindings/robovm-bro-gen/bro-gen.rb:2911:in `process': undefined method `visit_children' for an instance of FFI::Clang::Cursor (NoMethodError)

            cursor.visit_children do |cursor, _parent|
                  ^^^^^^^^^^^^^^^
	from /Users/roman/Downloads/bindings/robovm-bro-gen/bro-gen.rb:3974:in `block in <main>'
	from /Users/roman/Downloads/bindings/robovm-bro-gen/bro-gen.rb:3816:in `each'
	from /Users/roman/Downloads/bindings/robovm-bro-gen/bro-gen.rb:3816:in `<main>'

PromanSEW avatar Sep 09 '24 17:09 PromanSEW

@dkimitsa can you help please?

PromanSEW avatar Sep 10 '24 03:09 PromanSEW

@PromanSEW please open issue in https://github.com/dkimitsa/robovm-bro-gen project. its not related to ffi-clang

dkimitsa avatar Sep 10 '24 06:09 dkimitsa

meanwhile I can confirm that issues is with ffi-clang (0.10.0)

@PromanSEW i would revert to 0.9.0 for now

dkimitsa avatar Sep 10 '24 06:09 dkimitsa

@PromanSEW https://github.com/dkimitsa/robovm-bro-gen/issues/4

dkimitsa avatar Sep 10 '24 07:09 dkimitsa

@dkimitsa I wanted, but your project didn't have "Issues" tab in that time 🤷

PromanSEW avatar Sep 10 '24 07:09 PromanSEW

@dkimitsa anyway, fun fact, that devs broke the main "Usage" from README...

PromanSEW avatar Sep 10 '24 07:09 PromanSEW

@PromanSEW bro-gen fixed with https://github.com/dkimitsa/robovm-bro-gen/commit/f8f9c67cecd474e746e5de3f85ecf893ae39b535

dkimitsa avatar Sep 10 '24 18:09 dkimitsa

Sorry to cause a problem. This was a change I made, which replaces #visit_children with #each (a more idiomatic Ruby idiom). The PR was here:

https://github.com/ioquatix/ffi-clang/pull/80

cfis avatar Nov 03 '24 04:11 cfis

Forgive me for being out of touch but is there any actionable work here or are we good to close?

ioquatix avatar Nov 04 '24 06:11 ioquatix

The big benefit of switching to #each is that it is idiomatic Ruby and the Cursor class can then include Enumerable.

An actionable item could be be adding code like this for backwards compatibility:

alias visit_children each

However that is not quite the same as the fix in robovm-bro-gen which was:

    def visit_children(&block)
        each(recurse = false, &block)
    end

The difference is setting recurse to false instead of true. So the alias might not work in this case. (FYI I would love it if Enumerable methods like #find, #find_all, etc. could pass extra parameters to #each but from my testing that doesn't work).

cfis avatar Nov 04 '24 06:11 cfis

hello @ioquatix @cfis , thank you for comments, from robovm-bro-gen point of view we are good to go as already adapted to changes.

dkimitsa avatar Nov 04 '24 15:11 dkimitsa

Why don't we introduce the fix proposed by @dkimitsa

    def visit_children(&block)
        each(false, &block)
    end

I think you can write it like this:

node.visit_children.find(...)

Am I missing something?

ioquatix avatar Nov 04 '24 20:11 ioquatix

Fix released in v0.11.0. Thanks everyone.

ioquatix avatar Nov 13 '24 07:11 ioquatix