Skip to content

Improve default argument type mismatch errors#8389

Merged
cknitt merged 3 commits intomasterfrom
optional-default-match-error
Apr 24, 2026
Merged

Improve default argument type mismatch errors#8389
cknitt merged 3 commits intomasterfrom
optional-default-match-error

Conversation

@cknitt
Copy link
Copy Markdown
Member

@cknitt cknitt commented Apr 24, 2026

Summary

Improve the type error shown for optional arguments with invalid default values. Fixes #8387.

Optional argument defaults are lowered through a generated match, which previously caused type mismatches in the default value to be reported as if they came from a user-written switch. This tags the generated optional-default match internally and uses function-style diagnostics for that path instead.

Changes

  • Mark generated optional-default match expressions with an internal #optional_arg_default attribute.
  • Treat that generated match as function context when selecting type mismatch wording.
  • Add a super-errors fixture for an optional default argument type mismatch.
  • Regenerate super-errors snapshots.

Note

The snapshot regeneration also produced unrelated whitespace-only changes in a few existing expected files.

@cknitt cknitt requested a review from zth April 24, 2026 14:47
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 24, 2026

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 879c8a5

@cknitt cknitt changed the title Improve error for generated optional default match Improve optional default argument type mismatch errors Apr 24, 2026
@cknitt cknitt changed the title Improve optional default argument type mismatch errors Improve default argument type mismatch errors Apr 24, 2026
@cknitt cknitt merged commit 709f46f into master Apr 24, 2026
32 checks passed
@cknitt cknitt deleted the optional-default-match-error branch April 24, 2026 18:42
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.

Weird error message for incorrect default arg type

2 participants