Skip to content

Conversation

zth
Copy link
Member

@zth zth commented Aug 25, 2025

This is a pretty common gotcha - {ident} is counted as a block with an ident, not a record expr with a single field.

@zth zth force-pushed the error-braced-single-identifier-to-record branch from f620b1c to 1f24505 Compare August 25, 2025 14:55
@zth zth requested review from mediremi, nojaf and tsnobip August 25, 2025 14:55
Comment on lines 2259 to 2270
(* Special errors for braced identifiers passed to records *)
let context =
match sexp.pexp_desc with
| Pexp_ident _ ->
if
sexp.pexp_attributes
|> List.exists (fun (attr, _) -> attr.txt = "res.braces")
&& is_record_type ~extract_concrete_typedecl ~env ty_expected
then Some Error_message_utils.BracedIdent
else context
| _ -> context
in
Copy link
Member Author

Choose a reason for hiding this comment

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

@cristianoc I've tried to guard this lookup as much as possible, but do you think it's worth seeing if this processing could be moved to only happen if there's an actual type error? I guess I could catch and reraise.

Copy link
Member

@nojaf nojaf left a comment

Choose a reason for hiding this comment

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

Great improvement.
Makes me wonder if we should also write this somewhere on https://rescript-lang.org/docs/manual/v12.0.0/record#tips--tricks

Comment on lines 560 to 562
Possible solutions: @,\
- Return the expected record from the block@,\
- Write out the full record with field and value, like: @{<info>%s@}"
Copy link
Member

Choose a reason for hiding this comment

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

I think writing out the record fully without punning will be the most common fix, so maybe we should show it first in the list of possible solutions?

Suggested change
Possible solutions: @,\
- Return the expected record from the block@,\
- Write out the full record with field and value, like: @{<info>%s@}"
Possible solutions: @,\
- Write out the full record with field and value, like: @{<info>%s@}"
- Return the expected record from the block@,\

Copy link
Member Author

Choose a reason for hiding this comment

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

@mediremi good point. Done in the latest commit.

Copy link

pkg-pr-new bot commented Aug 25, 2025

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 92db0ba

@zth zth enabled auto-merge (squash) August 26, 2025 17:57
@zth zth merged commit f8c108f into master Aug 26, 2025
25 checks passed
@zth zth deleted the error-braced-single-identifier-to-record branch August 26, 2025 20:10
Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

Sweet

*)
and type_expect ~context ?in_function ?recarg env sexp ty_expected =
(* Special errors for braced identifiers passed to records *)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use example pattern, or else "braced identifier" is a bit difficult to understand for the comment reader.


Possible solutions:
- Write out the full record with field and value, like: {householdId: householdId}
- Return the expected record from the block No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

See if an llm (simple, non-thinking) understands this message and is able to fix the code.
Or else, try rephrasing.

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.

4 participants