Fix untyped_args misreading keyword params as positional - #46
Open
maedi wants to merge 3 commits into
Open
Conversation
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.
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.
Summary
Redefiner.untyped_args(the path used whenconfig.type_checkingisfalse) decided positional-vs-keyword by checkingparam_proxy.positiontruthiness:But keyword params also carry a non-nil
.position(their ordinal position among all params, not just positional ones) — so a keyword-typed param likegreeting: Stringgets misread as positional and looked up asargs[position], which is empty for a keyword call. That reads asnil, which trips the "required but missing" check and raisesLow::ArgumentTypeError— even with type checking supposedly disabled. This meanstype_checking = falseis currently unusable for any class with keyword type expressions.The working
typed_methodspath already decides this correctly, checking.typeinstead:Fix
Use that same check in
untyped_argsinstead of the position-truthiness check.Verification
#typed_kwargto bothtype_checking_disabled/type_checking_enabledfixtures and mirrored the existing#typed_argtest cases for it.redefiner.rbfix and reran — 3 of the new tests fail with exactly the describedLow::ArgumentTypeError, confirming they exercise the real bug rather than being incidentally green.main(all Ruby-version-dependent formatting differences in hash/error-message output, unrelated to this change).