Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add try..finally syntax#7903

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
cknitt wants to merge5 commits intomaster
base:master
Choose a base branch
Loading
fromtry-finally
Draft

Add try..finally syntax#7903

cknitt wants to merge5 commits intomasterfromtry-finally

Conversation

@cknitt
Copy link
Member

@cknittcknitt commentedSep 18, 2025
edited
Loading

Adds support fortry..finally andtry..catch..finally syntax to ReScript.
No breaking changes / full backwards compatibility.

Resolves#6974.

@pkg-pr-new
Copy link

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7903

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7903

@rescript/win32-x64

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

commit:4eb58f6

@cknittcknitt changed the title[PoC] try..finallyAdd try..finally syntaxSep 18, 2025
@cknittcknitt marked this pull request as ready for reviewSeptember 18, 2025 17:54
@fhammerschmidt
Copy link
Member

Maybe add atry await example to the tests.

attach t.trailing expr.pexp_loc after_expr;
walk_list (cases|>List.map (funcase ->Case case)) t rest
(* unary expression: todo use parsetreeviewer*)
|Pexp_try (expr,cases,finally_expr) -> (
Copy link
Collaborator

Choose a reason for hiding this comment

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

why was this case not handled at all before?
I would expect a change that only deals with finally, here

elseif
Parser.lookahead p (funstate ->
match state.Parser.tokenwith
|Lident"finally" ->true
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's finally in the grammar? just an identified?
Not a keyword I guess

}catch {
|InnerError=>Console.log("Inner caught")
}
}catch {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the indentation we want? Does TS look like this when formatted?

let finally_typed=
type_expect~context:None env exprPredef.type_unit
in
(* Finally blocks must return unit*)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

*)
|Texp_try of expression* caselist
(** try E with P1 -> E1 | ... | PN -> EN*)
|Texp_try of expression* caselist* expressionoption
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: get assistant to use a record in a hypothetical follow-up PR, if this goes ahead

Sexp.list (map_empty~f:case cases);
]
|Pexp_try (expr,cases) ->
|Pexp_try (expr,cases,finally_expr) ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

I keep on forgetting why we have this debugger file. Gives maintenance burden but can't remember why we need it.

|Lstaticraise ofint* tlist
|Lstaticcatch of t* (int* identlist)* t
|Ltrywith of t* ident* t
|Ltrywith of t* ident* toption* toption
Copy link
Collaborator

Choose a reason for hiding this comment

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

opportunity: this file is entirely uncommented
a separate PR couldassist in adding some explanation

More bigger / longer term assistance opportunity: why do we have both lambda and lam? Is that a historical artefact for what used to be backwards compatibility, or can they possibly be merged now?

P.string fL.finally;
P.space f;
brace_block cxt f b))
P.space f;
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious whyfin was already here

Copy link
Collaborator

@cristianoccristianoc left a comment

Choose a reason for hiding this comment

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

The PR should have a good amount of text in the description explaining what this PR does at high level.

@cknittcknitt marked this pull request as draftSeptember 20, 2025 06:30
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@cristianoccristianoccristianoc left review comments

@zthzthAwaiting requested review from zth

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Support try...finally

4 participants

@cknitt@fhammerschmidt@cristianoc

[8]ページ先頭

©2009-2025 Movatter.jp