Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix untyped_args misreading keyword params as positional - #46

Open
maedi wants to merge 3 commits into
mainfrom
fix/untyped-args-keyword-param-detection
Open

Fix untyped_args misreading keyword params as positional#46
maedi wants to merge 3 commits into
mainfrom
fix/untyped-args-keyword-param-detection

Conversation

@maedi

@maedi maedi commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

Redefiner.untyped_args (the path used when config.type_checking is false) decided positional-vs-keyword by checking param_proxy.position truthiness:

value = param_proxy.position ? args[param_proxy.position] : kwargs[param_proxy.name]

But keyword params also carry a non-nil .position (their ordinal position among all params, not just positional ones) — so a keyword-typed param like greeting: String gets misread as positional and looked up as args[position], which is empty for a keyword call. That reads as nil, which trips the "required but missing" check and raises Low::ArgumentTypeError — even with type checking supposedly disabled. This means type_checking = false is currently unusable for any class with keyword type expressions.

The working typed_methods path already decides this correctly, checking .type instead:

positional = %i[pos_req pos_opt].include?(param_proxy.type)

Fix

Use that same check in untyped_args instead of the position-truthiness check.

Verification

  • Added #typed_kwarg to both type_checking_disabled/type_checking_enabled fixtures and mirrored the existing #typed_arg test cases for it.
  • Confirmed the new tests actually catch the bug: stashed just the redefiner.rb fix and reran — 3 of the new tests fail with exactly the described Low::ArgumentTypeError, confirming they exercise the real bug rather than being incidentally green.
  • Full suite: 147 examples (141 existing + 6 new), same 10 pre-existing failures as main (all Ruby-version-dependent formatting differences in hash/error-message output, unrelated to this change).

maedi and others added 3 commits August 17, 2026 11:09
Redefiner.untyped_args (the path used when config.type_checking is
false) decided positional-vs-keyword by checking param_proxy.position
truthiness. Keyword params also carry a non-nil .position (their
ordinal position among all params, not just positional ones), so a
keyword-typed param like `greeting: String` got misread as positional
and looked up as args[position] -- empty for a keyword call -- which
reads as nil and trips the "required but missing" check, raising
Low::ArgumentTypeError. This meant type_checking = false was unusable
for any class with keyword type expressions.

Use the same %i[pos_req pos_opt].include?(param_proxy.type) check the
working typed_methods path already uses, instead of the
position-truthiness check.
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