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

Fix pattern inference and annotation requirements. #979

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

KtorZ
Copy link
Member

@KtorZ KtorZ commented Jul 24, 2024

Preview

Note

See also the added test scenarios.

code before after
image image image
image image image
image image image
image image image

Changlog

  • 📍 Fix casting inferrence on patterns
    The original goal for this commit was to allow casting from Data on
    patterns without annotation. For example, given some custom type
    'OrderDatum':

    expect OrderDatum { requested_handle, destination, .. }: OrderDatum = datum
    

    would work fine, but:

    expect OrderDatum { requested_handle, destination, .. } = datum
    

    Yet, the annotation feels unnecessary at this point because type can
    be inferred from the pattern itself. So this commit allows, whenever
    possible (ie when the pattern is neither a discard nor a var), to
    infer the type from a pattern.

    Along the way, I also found a couple of weird behaviours surrounding
    this kind of assignments, in particular in combination with let. I'll
    highlight those in the next PR (Fix pattern inference and annotation requirements. #979).

  The original goal for this commit was to allow casting from Data on
  patterns without annotation. For example, given some custom type
  'OrderDatum':

  ```
  expect OrderDatum { requested_handle, destination, .. }: OrderDatum = datum
  ```

  would work fine, but:

  ```
  expect OrderDatum { requested_handle, destination, .. } = datum
  ```

  Yet, the annotation feels unnecessary at this point because type can
  be inferred from the pattern itself. So this commit allows, whenever
  possible (ie when the pattern is neither a discard nor a var), to
  infer the type from a pattern.

  Along the way, I also found a couple of weird behaviours surrounding
  this kind of assignments, in particular in combination with let. I'll
  highlight those in the next PR (#979).
@KtorZ KtorZ self-assigned this Jul 24, 2024
@KtorZ KtorZ requested a review from a team as a code owner July 24, 2024 10:42
@KtorZ KtorZ merged commit 63863c9 into main Jul 25, 2024
12 checks passed
@KtorZ KtorZ deleted the fix_casting_inference branch July 25, 2024 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ In Next Release
Development

Successfully merging this pull request may close these issues.

1 participant