You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 052d3cc
Browse filesBrowse the repository at this point in the historyBrowse files
Refuse coercing another type into a private record or variant
Why:
A private type's values can only be built in the module that defines
it, but structural coercion built them anywhere: a plain record, another
module's private record with the same fields, a variant, a polymorphic
variant or a string coerced into a private record or variant (#9124).
`subtype_rec` refuses a coercion whose target's definition is a private
record or variant unless the source is that same type. Coercing out of a
private type is unchanged.
Typing modified (coercion into a private type):
Example:
module Blob: { type t = private {size: float} } = { type t = {size: float} }
type plain = {size: float}
let fake = (p: plain) => (p :> Blob.t)
Before (rule): a record coerces into a record with compatible fields,
private or not
After (rule): a record or variant coerces into a private record or variant
only from that same type
Diagnostic added (coercion into a private type):
Example:
let fake = (p: plain) => (p :> Blob.t)
Before (diagnostic): none
After (diagnostic):
Type plain is not a subtype of Blob.t
Blob.t is private: its values can only be built in the module that
defines it, so another type cannot be coerced to it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
- Coercing another type into a private record or variant is an error: only the module defining a private type can build its values. Coercing out of a private type still works.
0 commit comments