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

Dedicated error message for ternaries#7804

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

Merged
zth merged 2 commits intomasterfromerror-message-ternary
Aug 25, 2025
Merged

Conversation

@zth
Copy link
Member

@zthzth commentedAug 25, 2025

The general if error was used before (because that's what the ternary desugars to). This gives ternaries a dedicated error.

Comment on lines +2829 to +2840
(* TODO(attributes) Unify the attribute handling in the parser and rest of the compiler.*)
let is_ternary=
letrechas_ternary=function
|[] ->false
| ({Location.txt ="res.ternary"},_) ::_ ->true
|_ ::rest -> has_ternary rest
in
has_ternary sexp.pexp_attributes
in
let return_context=
if is_ternarythenSomeTernaryReturnelseSomeIfReturn
in
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Putting in my TODO to unify all of these attribute names across the syntax and compiler. A lot of them should probably be proper AST nodes.

Copy link
Member

Choose a reason for hiding this comment

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

Would be great to track this in an issue instead.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Done#7805

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a dedicated error message for ternary operators, distinguishing them from general if statement errors. Previously, ternary expressions used the same error messages as if statements since they desugar to if-then-else constructs.

  • Adds a newTernaryReturn context type to differentiate ternary expressions from if statements
  • Updates error message formatting to specifically mention ternaries with? and: operators
  • Adds test case demonstrating the new error message for type mismatches in ternary branches

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

FileDescription
compiler/ml/typecore.mlDetects ternary expressions via attributes and usesTernaryReturn context instead ofIfReturn
compiler/ml/error_message_utils.mlAddsTernaryReturn context type and corresponding error message formatting
tests/build_tests/super_errors/fixtures/ternary_branch_mismatch.resTest fixture with ternary type mismatch
tests/build_tests/super_errors/expected/ternary_branch_mismatch.res.expectedExpected error output showing the new ternary-specific error message

Tip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.

Comment on lines +2830 to +2833
let is_ternary=
letrechas_ternary=function
|[] ->false
| ({Location.txt ="res.ternary"},_) ::_ ->true

Choose a reason for hiding this comment

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

The magic string "res.ternary" should be defined as a constant to avoid duplication and make it easier to maintain if the attribute name changes.

Suggested change
let is_ternary=
letrechas_ternary=function
|[] ->false
| ({Location.txt ="res.ternary"},_) ::_ ->true
let res_ternary_attribute="res.ternary"in
let is_ternary=
letrechas_ternary=function
|[] ->false
| ({Location.txt =res_ternary_attribute},_) ::_ ->true

Copilot uses AI. Check for mistakes.
Copy link
Member

@mediremimediremi left a comment

Choose a reason for hiding this comment

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

Nice improvement 💪

@zthzthenabled auto-merge (squash)August 25, 2025 14:25
@pkg-pr-new
Copy link

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/win32-x64

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

commit:a080c4a

@zthzth merged commit3931a96 intomasterAug 25, 2025
36 of 37 checks passed
Copy link
Member

@tsnobiptsnobip left a comment

Choose a reason for hiding this comment

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

Nice improvement! Thanks@zth !

@zthzth deleted the error-message-ternary branchAugust 25, 2025 14:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nojafnojafnojaf approved these changes

Copilot code reviewCopilotCopilot left review comments

@tsnobiptsnobiptsnobip approved these changes

@mediremimediremimediremi approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@zth@tsnobip@nojaf@mediremi

[8]ページ先頭

©2009-2025 Movatter.jp