fix(type): wire up type.fn.raw at runtime#1631
Open
aarsh767 wants to merge 1 commit into
Open
Conversation
type.fn.raw was typed but always undefined at runtime, so calling it threw "type.fn.raw is not a function". The parser read `$.fn` while building its `attach` object, but `$.fn` is the InternalFnParser instance currently being constructed, so it was still undefined and got captured as `raw`. Extract the parser into a local `parse` function and reference it for both the callable body and `raw` so there's no longer a dependency on the half-initialized scope. Closes arktypeio#1609
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a runtime fix for type.fn.raw and a regression test.
- Extract the parser body into a local
parsefunction inInternalFnParserand use it as both the callable body and therawattachment, avoiding the uninitialized$.fnreference. - Add a
rawtest case toark/type/__tests__/fn.test.tsasserting it parses, runs, and validates likefn.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
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.

Closes #1609
type.fn.rawis typed as a function (an alias offnwith no type-level validation), but at runtime it's alwaysundefined, so calling it throwstype.fn.raw is not a function:Cause
InternalFnParserbuilds itsattachobject withraw: $.fn, but$.fnis the veryInternalFnParserinstance being constructed (scope.fn = new InternalFnParser(this)), so it's stillundefinedat that point.CallableappliesattachwithObject.assign, which copies the value, sorawpermanently capturesundefined(a lazy getter wouldn't help either, sinceObject.assignevaluates it).Fix
Extract the parser body into a local
parsefunction and reference it for both the callable body andraw. This removes the dependency on the half-initialized scope —rawandfnnow point at the same parser, which matches the documented "alias offn" behavior.Tests
Added a
rawcase toark/type/__tests__/fn.test.tsasserting it parses, runs, and validates likefn(including the same traversal error on bad input).