Skip to content

Remove the unused res.iflet encoding of if let - #8741

Merged
cknitt merged 2 commits into
masterfrom
remove-if-let-encoding
Oct 8, 2026
Merged

cknitt merged 2 commits into
masterfrom
remove-if-let-encoding

Conversation

@cknitt

@cknitt cknitt commented Oct 8, 2026

Copy link
Copy Markdown
Member

Stacked on #8740. Resolves the res.iflet item of #8624 by removing the encoding rather than giving it a node.

if let has been in the syntax since at least 2020 (as ns.iflet, renamed in #5862), but the parser always rejects it with a syntax error: "If-let is currently highly experimental. Use a regular switch with pattern matching instead", followed by the equivalent switch. There's no flag that enables it, and the formatter refuses files with syntax errors. Still, the parser encoded if let as a switch marked with res.iflet and @warning("-4"), and the viewer, printer and comment table carried code to print it back. The printer tests for it had already been commented out.

Changes

  • Parser: if let is still parsed for recovery and still reported with the same error and suggestion, but as a plain switch without the two attributes.
  • Viewer:
    • removed has_if_let_attribute, is_if_let_expr, the IfLet case of the if-chain condition (the if_condition_kind type goes away), filter_fragile_match_attributes, and res.iflet in is_parsing_attr;
    • without its res.iflet exception, has_attributes meant "has any attribute", so it's inlined at its callers.
  • Printer and comment table: removed the if let cases.
  • Tests: the commented-out if let printer tests are removed; the error test parsing/errors/expressions/ifLet.res keeps covering the message.

Behavior

  • The if let error message is unchanged; the error test's snapshot only shows the recovered tree without the attributes.
  • filter_fragile_match_attributes also applied to ordinary if expressions, so the formatter dropped a @warning("-4") written on an if. It's now kept.
  • Formatting of the repo's .res/.resi files is unchanged.

Tests

  • printer/expr/if.res: @warning("-4") on an if expression.

🤖 Generated with Claude Code

cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt added this pull request to stack #8739 October 8, 2026 07:46
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 2176c16 to d4c16cb Compare October 8, 2026 07:57
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.00%. Comparing base (18f3233) to head (121f150).

Files with missing lines Patch % Lines
compiler/syntax/src/res_printer.ml 87.50% 2 Missing ⚠️
compiler/syntax/src/res_parsetree_viewer.ml 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8741      +/-   ##
==========================================
+ Coverage   79.97%   80.00%   +0.02%     
==========================================
  Files         464      464              
  Lines       63232    63149      -83     
==========================================
- Hits        50571    50523      -48     
+ Misses      12661    12626      -35     
Files with missing lines Coverage Δ
compiler/syntax/src/res_comments_table.ml 91.25% <ø> (+2.12%) ⬆️
compiler/syntax/src/res_core.ml 91.95% <100.00%> (-0.01%) ⬇️
compiler/syntax/src/res_parens.ml 83.70% <100.00%> (-0.07%) ⬇️
compiler/syntax/src/res_parsetree_viewer.ml 94.00% <0.00%> (+0.99%) ⬆️
compiler/syntax/src/res_printer.ml 93.54% <87.50%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8741

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8741

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8741

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8741

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8741

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8741

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8741

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8741

commit: 121f150

cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from d4c16cb to c1e74d3 Compare October 8, 2026 08:28
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from c1e74d3 to 61064dd Compare October 8, 2026 08:35
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 61064dd to 77fe3be Compare October 8, 2026 09:39
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 77fe3be to 2052ecc Compare October 8, 2026 09:48
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 2052ecc to c443016 Compare October 8, 2026 10:04
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from c443016 to c316d52 Compare October 8, 2026 10:12
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from c316d52 to 7a64333 Compare October 8, 2026 12:09
@cknitt
cknitt marked this pull request as ready for review October 8, 2026 14:26
@cknitt

cknitt commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T14:29:52.861143Z 7a64333 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 7a6433366b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 7a64333 to e998570 Compare October 8, 2026 16:30
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from e998570 to 400196a Compare October 8, 2026 16:35
cknitt added a commit that referenced this pull request Oct 8, 2026
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 400196a to 2d8f340 Compare October 8, 2026 16:58
@cknitt
cknitt requested a review from cristianoc October 8, 2026 16:59
@cknitt
cknitt removed this pull request from stack #8739 October 8, 2026 17:55
@cknitt
cknitt added this pull request to stack #8743 October 8, 2026 17:55
Base automatically changed from remove-obsolete-attribute-filters to master October 8, 2026 17:57
cknitt and others added 2 commits October 8, 2026 19:57
The parser always rejects `if let` with a syntax error that suggests the
equivalent `switch`, and the formatter refuses files with syntax errors.
Still, the parser encoded `if let` as a `switch` marked with `res.iflet`
and `@warning("-4")`, and the viewer, printer and comment table carried
code to print it back. Its printer tests had been commented out.

Parse `if let` into a plain `switch` for recovery, keep the error, and
remove the encoding: `has_if_let_attribute`, `is_if_let_expr`, the
`IfLet` condition kind, `filter_fragile_match_attributes`, the
comment-table case, and `res.iflet` in `is_parsing_attr`. Without the
`res.iflet` exception, `has_attributes` meant "has any attribute" and is
inlined. The commented-out `if let` printer tests are removed.

`filter_fragile_match_attributes` also dropped a `@warning("-4")` written
on an ordinary `if` when formatting; it's now kept.

Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <christoph@knittel.cc>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cknitt
cknitt force-pushed the remove-if-let-encoding branch from 2d8f340 to 121f150 Compare October 8, 2026 17:57
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

@cknitt
cknitt merged commit 944c476 into master Oct 8, 2026
24 checks passed
@cknitt
cknitt deleted the remove-if-let-encoding branch October 8, 2026 18:35
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