Skip to content

fix(type): support nilable elements in ArrayOf and HashOf case equality - #100

Open
Adityakk9031 wants to merge 1 commit into
context-dot-dev:mainfrom
Adityakk9031:fix/nilable-collection-pattern-matching
Open

Adityakk9031 wants to merge 1 commit into
context-dot-dev:mainfrom
Adityakk9031:fix/nilable-collection-pattern-matching

Conversation

@Adityakk9031

Copy link
Copy Markdown

When defining ArrayOf or HashOf with nil?: true (e.g. ArrayOf[String, nil?: true]), #coerce accepts nil elements and records exactness appropriately.

However, case equality (===) did not take nilable? into account:

  • In ArrayOf, other.all?(item_type) evaluated item_type === nil, which returned false.
  • In HashOf, pattern matching only looked for in [Symbol | String, ^type], similarly rejecting nil values.

This caused === pattern matching and variant matching in Union#dump to fail whenever arrays or hashes contained nil items.

Updated ArrayOf#=== and HashOf#=== to permit nil elements when nilable? is true, and added unit tests in base_model_test.rb.

cc @contextualbeer

@Adityakk9031

Copy link
Copy Markdown
Author

Hi @contextualbeer, whenever you have a chance, could you please take a look at this PR? Thank you!

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