Skip to content

improve error message for trying to do dot access on option/array #7732

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

Merged
merged 3 commits into from
Jul 29, 2025

Conversation

zth
Copy link
Collaborator

@zth zth commented Jul 28, 2025

This improves the error message for trying to do dot access for a record field, but on something that's an option/array.

This error has been bugging me and others for a long time, because it's so non-obvious that you encountered an option (the old message didn't say) and need to unwrap.

Perfect for an action later on if we ever add optional chaining or similar.

@zth zth requested review from cknitt and cristianoc July 28, 2025 20:17
@zth zth force-pushed the record-access-on-option-error-message branch from dc7a7f6 to 57c0289 Compare July 28, 2025 20:19
Copy link

pkg-pr-new bot commented Jul 28, 2025

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/win32-x64

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

commit: ed7c2fb

(* TODO: Extend for nullable/null? *)
Format.fprintf ppf
"@[<v>You're trying to access the record field @{<info>%a@}, but the \
thing you're trying to access it on is an @{<info>option@}.@ You need \
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe 'value' instead of 'thing'?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in ed7c2fb. Any other feedback?

@zth zth requested a review from jderochervlk July 29, 2025 12:42
@zth zth merged commit f04e3b3 into master Jul 29, 2025
27 checks passed
@zth zth deleted the record-access-on-option-error-message branch July 29, 2025 16:13
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