Fix Tapioca Compiler to Preserve Params for Empty FixedHash#699
Conversation
c27df22 to
def4c34
Compare
def4c34 to
887bdfe
Compare
lib/tapioca/dsl/compilers/job_iteration.rbLine Comment (line 89):🐛 Bug: The new empty- Suggestion: Preserve the original if hash_type.types.empty?
typed_param
else
hash_type.types.map do |key, value|
if value.name.start_with?("T.nilable")
create_kw_opt_param(key.to_s, type: value.to_s, default: "nil")
else
create_kw_param(key.to_s, type: value.to_s)
end
end
endIf special handling is needed for genuinely optional empty-hash params, branch on |
There was a problem hiding this comment.
Pull request overview
Fixes Tapioca’s JobIteration DSL compiler so that an empty T::Types::FixedHash parameter ({}) does not get “exploded away” into zero parameters when generating RBIs, preserving the original positional parameter instead.
Changes:
- Preserve the original positional parameter when a FixedHash has zero keys (instead of flattening to an empty parameter list).
- Extract FixedHash expansion logic into a dedicated private helper to reduce nesting.
- Add regression tests covering empty FixedHash params and ensuring all-nilable FixedHash keys still expand to optional keyword args.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/tapioca/dsl/compilers/job_iteration.rb |
Adds expand_fixed_hash helper and ensures empty FixedHash parameters remain as positional params in generated method signatures. |
test/tapioca/dsl/compilers/job_iteration_test.rb |
Adds test coverage for empty FixedHash handling and all-nilable FixedHash key expansion behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
The tapioca DSL compiler for JobIteration explodes FixedHash types into keyword arguments on the generated
perform/perform_now/perform_latermethods. When the FixedHash is empty ({}),hash_type.types.mapreturns[], andflat_mapreplaces the positionalparamsparameter with nothing — generating zero-arg methods.This means a job like:
Any call site using perform_now({}) then fails with Sorbet error 7004 (too many arguments).
Fix
When the FixedHash has zero keys, preserve the original positional parameter as-is instead of exploding to nothing:
The param stays required because the runtime method chain (
perform(*params) → build_enumerator(*arguments, cursor:)) splats caller arguments directly — an RBI default does not exist at runtime, soperform_now()with zero args would raiseArgumentErrorinbuild_enumerator. Callers must passperform_now({}).Non-empty FixedHash explosion is unchanged — all existing behavior is preserved.
Also extracted
expand_fixed_hashprivate method to keep block nesting within rubocop's 3-level limit (Metrics/BlockNesting).Tests
test_generates_correct_rbi_file_for_job_with_empty_fixed_hash_parameter— verifies the fixtest_generates_correct_rbi_file_for_job_with_all_nilable_fixed_hash_keys— verifies all-optional keys still explode to optional kwargs (no regression)