Skip to content

Inconsistency between CRuby and TruffleRuby with pattern matching #3678

Open
@Th3-M4jor

Description

@Th3-M4jor

When using pattern matching on a HashWithIndifferentAccess from ActiveSupport there appears to be a difference in behavior.

Given the below example, using ActiveSupport 7.2.1

require 'active_support/all'

test = HashWithIndifferentAccess.new('a' => true)

case test
in {a: b}
  b
else
  false
end

When run on CRuby 3.3.5 it will return true, while on TruffleRuby 24.2.0-dev-512427a6 it'll return false

This appears to work on CRuby because of three things:

  • HashWithIndifferentAccess extends Hash
  • Hash#deconstruct_keys returns self
  • The resulting iseq calls .key? followed by .[] on the returned object

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions