Skip to content

[v2] feat(ast): add CatchClause::kind - #2023

Closed
hedgar2017 wants to merge 2 commits into
mainfrom
az/v2-catch-clause-kind
Closed

[v2] feat(ast): add CatchClause::kind#2023
hedgar2017 wants to merge 2 commits into
mainfrom
az/v2-catch-clause-kind

Conversation

@hedgar2017

@hedgar2017 hedgar2017 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Error and Panic catch clauses both bind to the same built-in, so the kind a clause declares is not recoverable from the binding. The structure pass already decides it from the selector name to reject invalid and duplicate clauses; move that decision onto the IR node and read it from both the pass and the AST.

@hedgar2017
hedgar2017 requested review from a team as code owners August 4, 2026 09:46
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9da1e74

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchaz/v2-catch-clause-kind
Testbedci

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🐰 View full continuous benchmarking report in Bencher

@hedgar2017
hedgar2017 force-pushed the az/v2-catch-clause-kind branch from c6e6930 to 491fe29 Compare August 4, 2026 10:03

@ggiraldez ggiraldez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not convinced this is a good approach. The problem with the binding mentioned in the PR description is not fixed by this. If it makes sense, we should split BuiltIn::ErrorOrPanic into BuiltIn::Error and BuiltIn::Panic. Other than that, there are other ways to distinguish the clause kinds, even not resorting to name string comparisons. The parameter types captured at each clause have distinct types (which we should validate, but that's not done yet).

Also, since the valid clauses are very much restricted and since the number of possible variants is fixed, we should probably normalize this at the IR and provide the AST with a CatchClauseKind IR enum node which binds the parameters. Eg.

enum CatchClauseKind {
  Error(ErrorClause),
  Panic(PanicClause),
  Lowlevel(LowlevelClause),
  UnboundLowlevel,
}

(Ideally we would elide the *Clause types and go with Parameters directly, but the IR model has some limitations)

Finally, CatchClauseKind moving to common seems off to me. It's a small detail in one diagnostic, nothing more. If we were to lift it up semantically, it makes more sense to have it as a IR construct.

@hedgar2017
hedgar2017 requested a review from ggiraldez August 5, 2026 13:08
@hedgar2017

Copy link
Copy Markdown
Contributor Author

@ggiraldez, thanks! Please check if the 2nd commit makes more sense.

`Error` and `Panic` catch clauses both bind to the same built-in, so the kind a
clause declares is not recoverable from the binding. The structure pass already
decides it from the selector name to reject invalid and duplicate clauses; move
that decision onto the IR node and read it from both the pass and the AST.

`CatchClauseKind` was declared inside the `DuplicateCatchClause` diagnostic that
carries it; give it a home of its own among the language-level enums in `common`,
so that neither the IR nor the AST names a type owned by a diagnostic.
@hedgar2017 hedgar2017 self-assigned this Aug 5, 2026
Supersedes the hand-written node extensions; the kind is classified once in the
CST-to-IR builder, mirroring FunctionKind.
@ggiraldez

Copy link
Copy Markdown
Contributor

I submitted #2031 which supersedes this PR. The clause kind is now encoded in the IR/AST types and at the same time we ensure that only valid clauses appear in the IR.

Sorry for the noise with the failed run. I had pushed a commit here but it overwrote all the existing changes, so I decided to open a new PR instead.

@teofr

teofr commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I'll close it since #2031 replaced it
cc @hedgar2017 @ggiraldez reopen if I shouldn't have

@teofr teofr closed this Aug 7, 2026
@hedgar2017
hedgar2017 deleted the az/v2-catch-clause-kind branch August 7, 2026 17:32
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.

3 participants