fix: discriminate overloaded function args#156
Open
FarajiOranj wants to merge 1 commit into
Open
Conversation
`FunctionArgs` (and `ConstructorArgs`/`EventArgs`) for an overloaded entry
inferred a plain union of each overload's args, which let callers mix args
from different overloads (e.g. `{ num, name }` for `foo(uint256) | foo(string)`).
Wrap `AbiObjectType` in a new `OneOfNamed` discriminated-union helper so only a
single overload's args can be used at a time. `OneOfNamed` is like `OneOf` but
counts only named keys (so a no-arg overload's empty object doesn't pollute the
other members with index signatures) and leaves a non-union type unchanged;
the widely-used `OneOf` is untouched. `FunctionReturn` is unaffected.
Adds `OneOfNamed`/`NamedUnionKey` utilities and type-tests.
🦋 Changeset detectedLatest commit: 01df456 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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
Closes #132.
Makes the inferred args type for overloaded functions (and events) a
discriminated union, so only the arguments of a single overload can be used at a
time.
Before, for an overloaded
foo(uint256 num)/foo(string name):After:
Changes
AbiObjectType(inAbi.ts) now wraps its result in a discriminated union.This flows into
FunctionArgs,ConstructorArgs, andEventArgs(all args).FunctionReturnusesAbiSimplifiedTypeand is intentionally unchanged, soreturn values stay a plain union.
OneOfNamedandNamedUnionKey.OneOfNamedislike the existing
OneOf, but it only counts named keys when negating othermembers and returns a non-union type unchanged. This keeps it correct when an
overload set includes a no-arg signature (whose "empty" object would otherwise
poison the other members with
[x: string]: undefinedindex signatures), andavoids changing the widely-used
OneOf(soCallParams/prepareCalletc. areunaffected).
Tests
Added
Function.test-d.tstype-tests covering discrimination for overloads withdifferent arg names, different arity, shared names, and a no-arg-plus-named
overload set, plus no-regression checks for single/no-arg functions and
FunctionReturn. This is a type-only change, so the runtime suite is unchanged.