Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Dec 8, 2025

Backend fix of #1335
Fix call-seq deduplicate of Hash#value? and Hash#has_value?.
When alias names have overlap, deduplicate didn't work correctly.

@tompng tompng temporarily deployed to fork-preview-protection December 8, 2025 18:04 — with GitHub Actions Inactive
if ignore.any?
ignore_union = Regexp.union(ignore)
entries.reject! do |entry|
entry =~ /^(\w*\.)?#{ignore_union}([\(\s]|$)/ or
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change
/^\w*\.?#{ignore_union}[$\(\s]/

/^(\w*\.)?#{ignore_union}([\(\s]|$)/

^\w*\.?value?[$\(\s] matches to has_value?, but we only want to ignore value? and receiver.value?
Fix is: \w*\.?(\w*\.)?

The latter part [$\(\s], $ seems like a mistake of $ (end-of-line), not "$" (dollar character)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, with this change, receiver[arg] won't be handled here.
So I added bracket_method remove logic in line 375-379.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $\(\s] pattern was added by #897 .

The latter part [$\(\s], $ seems like a mistake of $ (end-of-line), not "$" (dollar character)

I think that the assumption is correct.

@matzbot
Copy link
Collaborator

matzbot commented Dec 8, 2025

🚀 Preview deployment available at: https://d1d6844d.rdoc-6cd.pages.dev (commit: 35d3352)

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

It may be better that we extract method names from "call_seq" and compare method names instead of creating (complex) regular expressions to match raw "call_seq"...

ignore_union = Regexp.union(ignore)
entries.reject! do |entry|
entry =~ /^(\w*\.)?#{ignore_union}([\(\s]|$)/ or
entry =~ /\s#{ignore_union}\s/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entry =~ /\s#{ignore_union}\s/
/^(\w*\.)?#{ignore_union}([\(\s]|$)/.match?(entry) or
\s#{ignore_union}\s/.match?(entry)

BTW:

  • Can we use \A/\z not ^/$ here?
  • Can we remove needless \ escape from [\(]?
  • How about using (?:...) not (...) not referred groups?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

if ignore.any?
ignore_union = Regexp.union(ignore)
entries.reject! do |entry|
entry =~ /^(\w*\.)?#{ignore_union}([\(\s]|$)/ or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $\(\s] pattern was added by #897 .

The latter part [$\(\s], $ seems like a mistake of $ (end-of-line), not "$" (dollar character)

I think that the assumption is correct.

@tompng tompng force-pushed the callseq_dedupe_fix branch from 36d5137 to 14e858e Compare December 9, 2025 14:28
@tompng tompng requested a deployment to fork-preview-protection December 9, 2025 14:28 — with GitHub Actions Waiting
@tompng tompng force-pushed the callseq_dedupe_fix branch from 14e858e to 30e4865 Compare December 9, 2025 14:34
@tompng tompng temporarily deployed to fork-preview-protection December 9, 2025 14:34 — with GitHub Actions Inactive
@tompng
Copy link
Member Author

tompng commented Dec 9, 2025

It may be better that we extract method names from "call_seq"

I agree. I think call-seq's name part and params part extraction needs refactor.
But I'd like to fix this change in regexp way for now.

AnyMethod#name already have a name extraction from call-seq, but the logic seems incomplete. It doesn't handle method like foo!, foo?.

def name
    return @name if @name

    @name =
      @call_seq[/^.*?\.(\w+)/, 1] ||
      @call_seq[/^.*?(\w+)/, 1] ||
      @call_seq if @call_seq
  end

Maybe we can have a call-seq common format parser and use it in deduplicate_call_seq, name, param_list and param_seq but it will be a relatively large change.

Fix call-seq deduplicate of `Hash#value?` and `Hash#has_value?`.
When alias names have overlap, deduplicate didn't work correctly.
@tompng tompng force-pushed the callseq_dedupe_fix branch from 30e4865 to 35d3352 Compare December 9, 2025 17:54
@tompng tompng deployed to fork-preview-protection December 9, 2025 17:55 — with GitHub Actions Active
@st0012 st0012 added the bug label Dec 9, 2025
@tompng tompng merged commit 325a923 into ruby:master Dec 9, 2025
33 checks passed
@tompng tompng deleted the callseq_dedupe_fix branch December 9, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants