Open
Conversation
7cb3ddf to
cce64c5
Compare
cce64c5 to
4511c12
Compare
Contributor
Does this actually cause problems? Is the default used for type checking (other than the presence / absence of a default value)?
Given |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Tapioca JobIteration DSL compiler expands a
build_enumeratorparams argument typed as a Sorbet shape (T::Types::FixedHash) into separate keyword parameters onperform/perform_now/perform_ltaer.For optional shape keys, Sorbet represents the value as
T.nilable(inner), which at runtime is aT::Types::Union. The compiler already turned those intoKwOptParams, but it always used default:"nil". For an innerT::Hash[...](or untyped Hash), the natural Ruby default for an optional keyword is{}, notnil. Generating nil makes the RBI misleading and out of line with typical call sites.This change keeps default: "nil" for non-hash nilable types and uses default: "{}" when the nilable’s non-nil inner type is hash-like (T::Types::TypedHash or Simple with Hash).
Problem
Before — shape with an optional hash flag:
Generated RBI include flags as:
After— same signature, generated RBI matches the usual default for an optional hash keyword:
Proposed solution
Detect nilable FixedHash values via the runtime type, not only
name.start_with?("T.nilable"):require T::Types::Union, then useunwrap_nilableto get the non-nil inner type (same representation Sorbet uses forT.nilable).Choose the RBI default string from that inner type:
If it is hash-like —
T::Types::TypedHash(e.g.T::Hash[K, V]) orT::Types::Simplewithraw_type == Hash — use "{}". Otherwise use "nil" (unchanged for e.g.T.nilable(Integer)).