Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern types #1721

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

pattern types #1721

wants to merge 12 commits into from

Conversation

turadg
Copy link
Member

@turadg turadg commented Aug 13, 2023

refs: #2392

Description

Make mustMatch assert type implied by matcher.

TODO: rebase onto master. I have a working branch for that but it needs more work before overwriting this remote.

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

Upgrade Considerations

Comment on lines +99 to 104
* @template {string} [T=string] tag
* @typedef {{
* [Symbol.toStringTag]: string,
* [Symbol.toStringTag]: T,
* payload: Passable,
* [passStyle: symbol]: 'tagged' | string,
* }} CopyTagged
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this equate CopyTagged with CopyTagged<string>, which is novel and unexpected because "string" is not a known tag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I don't think CopyTagged<string> would satisfy the template because the parameter wouldn't be a string itself. It would have to by CopyTagged<'string'>. That's not a known tag but it was valid before, right? (i.e. not a regression).

if (harden.isFake) {
if ('isFake' in harden) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What motivates these changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the line started erroring because harden doesn't have an isFake property. I figure something in my changes fixed a resolution that had been falling back to any

mergify bot added a commit to Agoric/agoric-sdk that referenced this pull request Jul 12, 2024
refs: #6160

## Description

I ran again into the need for type narrowing with a shape object: https://github.com/Agoric/agoric-sdk/pull/8385/files#diff-b17d46d065ac769cdf1d70471b16d141f28672965c18522d58d39722d4852ad4R329-R331

endojs/endo#1721 approached the general problem of inferring the type from the shape. But until we have that, we can at least move the type description onto the shape object so users of that shape can automatically get the type a match implies.

With this, the code referenced above would be,
```js
const questionDesc = cast(info, QuestionSpecShape);
```

### Security Considerations

n/a
### Scaling Considerations

n/a

### Documentation Considerations

Once this settles in agoric-sdk, we may want to move it into Endo. Alternately, Endo waits for more general support.

### Testing Considerations

Has a test. Maybe should use tsd instead of Ava

### Upgrade Considerations

n/a
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.

2 participants