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

Refinements take place at block passing #8097

Open
Tracked by #6161
headius opened this issue Feb 9, 2024 · 0 comments
Open
Tracked by #6161

Refinements take place at block passing #8097

headius opened this issue Feb 9, 2024 · 0 comments

Comments

@headius
Copy link
Member

headius commented Feb 9, 2024

See https://bugs.ruby-lang.org/issues/14223

using Module.new {
	refine String do
		def to_proc
			proc { |it| it.send self }
		end

		def refine_method
			"X#refine_method"
		end
	end
}

def func &block
end

p "upcase".refine_method
# => "X#refine_method"

p "upcase".to_proc.call "homu"
# => "HOMU"

# Error: wrong argument type X (expected Proc) (TypeError)
func &"upcase"

The final line should work, but raises. We don't handle this because the to_proc call is happening inside CallNode logic, with the string being passed as the block operand. We should move the to_proc call outside of the invocation so it can cache and inline and all.

@headius headius mentioned this issue Feb 9, 2024
28 tasks
@headius headius changed the title Refinements take place at block passing Feature #14223 Refinements take place at block passing Feb 9, 2024
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

No branches or pull requests

1 participant