Skip to content

Conversation

@yancya
Copy link

@yancya yancya commented Feb 11, 2026

Summary

  • init_query_cursor() in ext/tree_sitter/query_cursor.c had three methods defined twice, producing Ruby warnings on require 'tree_sitter':
    warning: method redefined; discarding old exec
    warning: method redefined; discarding old match_limit
    warning: method redefined; discarding old match_limit=
    
  • exec: rb_define_module_function internally defines both a singleton method and an instance method, then rb_define_method redefined the instance method → replaced with rb_define_singleton_method
  • match_limit / match_limit=: DECLARE_ACCESSOR macro and explicit rb_define_method calls both defined the same methods → removed the DECLARE_ACCESSOR call

Test plan

  • Added test/tree_sitter/query_cursor_test.rb that verifies no "method redefined" warnings are emitted when loading the extension
  • Test fails on master (warnings present), passes with fix (warnings gone)
  • bundle exec rake compile succeeds without errors

🤖 Generated with Claude Code

…warnings

`init_query_cursor()` had three methods defined twice:
- `exec`: `rb_define_module_function` (which internally defines both a
  singleton and instance method) followed by `rb_define_method`
- `match_limit` / `match_limit=`: `DECLARE_ACCESSOR` macro followed by
  explicit `rb_define_method` calls

This produced Ruby warnings on require:
  warning: method redefined; discarding old exec
  warning: method redefined; discarding old match_limit
  warning: method redefined; discarding old match_limit=

Fix:
- Replace `rb_define_module_function` with `rb_define_singleton_method`
  for the class-level `exec`, so it no longer conflicts with the
  instance-level `rb_define_method`
- Remove the `DECLARE_ACCESSOR` macro call, keeping the explicit
  `rb_define_method` calls for `match_limit` and `match_limit=`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant