Skip to content

Treat Variant[..., Undef] as optional#7

Merged
alexjfisher merged 1 commit intovoxpupuli:masterfrom
kasimon:variant-undef-optional
Feb 27, 2026
Merged

Treat Variant[..., Undef] as optional#7
alexjfisher merged 1 commit intovoxpupuli:masterfrom
kasimon:variant-undef-optional

Conversation

@kasimon
Copy link
Contributor

@kasimon kasimon commented Feb 27, 2026

Summary

  • Fixes Check does not accept Variant[..., Undef] as a valid definition #5
  • Adds variant_with_undef? helper that checks whether a Variant type contains Undef as a direct member (at depth 1)
  • Skips the "not optional parameter defaults to undef" warning for such types, since Variant[String, Undef] is functionally equivalent to Optional[String]
  • Adds test cases for Variant[String, Undef] and Variant[String, Integer, Undef]

Test plan

  • All 17 specs pass (bundle exec rake spec)
  • Existing Variant[String[0], Integer] and Variant[Any, Optional] tests still warn correctly

Variant types containing Undef as a direct member (e.g. Variant[String, Undef])
are functionally equivalent to Optional and should not trigger the
"not optional parameter defaults to undef" warning.
Copy link
Member

@alexjfisher alexjfisher left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you!

@alexjfisher alexjfisher merged commit b4f719f into voxpupuli:master Feb 27, 2026
5 checks passed
@kasimon kasimon deleted the variant-undef-optional branch February 27, 2026 14:46
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.

Check does not accept Variant[..., Undef] as a valid definition

2 participants