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

.is_a? works with constant values #15389

Open
Blacksmoke16 opened this issue Jan 30, 2025 · 2 comments
Open

.is_a? works with constant values #15389

Blacksmoke16 opened this issue Jan 30, 2025 · 2 comments

Comments

@Blacksmoke16
Copy link
Member

Bug Report

This came up in the Discord and was surprised this even works:

require "http/status"

pp HTTP::Status::OK.is_a? HTTP::Status::OK        # => true
pp HTTP::Status::NOT_FOUND.is_a? HTTP::Status::OK # => false

Or more simply:

NUM = 1
 
pp NUM.is_a? NUM # => true

Is this expected?

@straight-shoota
Copy link
Member

Seems odd. I suppose it behaves similar to #==?

@HertzDevil
Copy link
Contributor

HertzDevil commented Jan 31, 2025

Duplicate of #11371?

Apparently the compiler relies on this behavior during expansion of case expressions, and A.is_a?(B) becomes B === A.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants