Skip to content

Compare the @as tags of variant cases with payloads across signatures - #9009

Merged
cknitt merged 1 commit into
masterfrom
variant-payload-tags-signature
Oct 24, 2026
Merged

cknitt merged 1 commit into
masterfrom
variant-payload-tags-signature

Conversation

@cknitt

@cknitt cknitt commented Oct 24, 2026

Copy link
Copy Markdown
Member

Fixes #8956.

Interface inclusion compared the @as literal of nullary cases only. An implementation could swap the tags of two cases with payloads, and its clients then matched M.A(_) as C:

module M: {
  type t = A({x: int}) | C({x: int})
  let a: t
} = {
  type t = | @as("C") A({x: int}) | @as("A") C({x: int})
  let a = A({x: 1})
}
Console.log(switch M.a { | M.A(_) => "A" | M.C(_) => "C" })   // C

Includecore.compare_variants now compares the tags of tagged cases with a payload as it does those of nullary cases. An untagged case's @as does not change its representation (spec rule 2) and is not compared. Type declarations in messages now print the @as of tagged cases with a payload too (printtyp.ml:tree_of_constructor); before, both sides of this mismatch printed as A({x: int}) | C({x: int}):

Type declarations do not match:
  type t = @as("C") A({x: int}) | @as("A") C({x: int})
is not included in
  type t = A({x: int}) | C({x: int})
The internal representations for case A are not equal.

UntaggedVariants.md: rule 14 states the comparison, and the known bug is removed.

New test: super_errors/variant_payload_tag_mismatch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t

Why:
    Interface inclusion compared the `@as` literal of nullary cases only. An
    implementation could swap the tags of two cases with payloads, and its
    clients then matched `M.A(_)` as `C` (#8956).

The tags of tagged cases with a payload are compared as those of nullary
cases are. An untagged case's `@as` does not change its representation and
is not compared. Type declarations in messages now print the `@as` of a
tagged case with a payload too, so the mismatch shows.

Diagnostic added:
Example:
    module M: {
      type t = A({x: int}) | C({x: int})
    } = {
      type t = | @as("C") A({x: int}) | @as("A") C({x: int})
    }
After (diagnostic):
    Type declarations do not match:
      type t = @as("C") A({x: int}) | @as("A") C({x: int})
    is not included in
      type t = A({x: int}) | C({x: int})
    The internal representations for case A are not equal.

Fixes: #8956
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
@github-actions

Copy link
Copy Markdown

Changelog

  • 🐛 Reject an implementation whose variant cases with a payload have other @as tags than the interface states, and print those tags in type declarations.

Semantic Diff

1 commit · Full page

Compare the @as tags of variant cases with payloads across signatures

ed8d4a4 · cknitt + Claude · Oct 24, 2026, 06:14 UTC

Why

Interface inclusion compared the @as literal of nullary cases only. An implementation could swap the tags of two cases with payloads, and its clients then matched M.A(_) as C (#8956).

The tags of tagged cases with a payload are compared as those of nullary cases are. An untagged case's @as does not change its representation and is not compared. Type declarations in messages now print the @as of a tagged case with a payload too, so the mismatch shows.

Diagnostic added

module M: {
  type t = A({x: int}) | C({x: int})
} = {
  type t = | @as("C") A({x: int}) | @as("A") C({x: int})
}

diagnostic · After

Type declarations do not match:
  type t = @as("C") A({x: int}) | @as("A") C({x: int})
is not included in
  type t = A({x: int}) | C({x: int})
The internal representations for case A are not equal.

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.29%. Comparing base (d8db3c6) to head (ed8d4a4).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
compiler/ml/printtyp.ml 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9009   +/-   ##
=======================================
  Coverage   81.29%   81.29%           
=======================================
  Files         456      456           
  Lines       63836    63843    +7     
=======================================
+ Hits        51893    51899    +6     
- Misses      11943    11944    +1     
Files with missing lines Coverage Δ
compiler/ml/includecore.ml 78.46% <100.00%> (+0.42%) ⬆️
compiler/ml/printtyp.ml 70.55% <80.00%> (-0.05%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9009

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: ed8d4a4

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@cknitt
cknitt marked this pull request as ready for review October 24, 2026 06:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T06:40:35.222592Z ed8d4a4 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: ed8d4a46c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt requested a review from cristianoc October 24, 2026 06:44
@cknitt
cknitt merged commit 44309a2 into master Oct 24, 2026
26 checks passed
@cknitt
cknitt deleted the variant-payload-tags-signature branch October 24, 2026 08:43
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.

Signature does not compare @as tags of variant cases with payloads

2 participants