Add Maybe.some / Maybe.none constructors with T->Maybe<T> coercion#186
Open
WalterGropius wants to merge 4 commits into
Open
Add Maybe.some / Maybe.none constructors with T->Maybe<T> coercion#186WalterGropius wants to merge 4 commits into
WalterGropius wants to merge 4 commits into
Conversation
Mirrors the choice-style constructor pattern so users can construct present Maybe values explicitly with Maybe.some(value) or Maybe.none. In a context that expects Maybe<T>, a plain T value coerces to Maybe.some(value); null and Maybe.none remain Maybe absences. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ercion Reuses the existing IR_VALUE_MAYBE_SCALAR_LITERAL opcode so no new IR or aarch64 lowering is required. Non-literal Maybe.some payloads and non-scalar element types fall back to CGEN004 like other MVP gaps. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds runtime-or-unsupported fixtures for Maybe.some and the plain-T-to-Maybe<T> coercion in returns, plus a TYP011 fail fixture for bare Maybe.none without an explicit context. Refreshes the language-reference Maybe paragraph to mention the new constructors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The TYP011 message now covers both bare null and bare Maybe.none, so zero explain TYP011 surfaces a short rationale and a paired bad/good example. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@WalterGropius is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds explicit
Maybe.some(value)andMaybe.noneconstructors, mirroringthe choice-style pattern, and lets a plain
Tvalue coerce toMaybe.some(value)in any position that already expectsMaybe<T>(return, let-with-annotation, or argument). The existing
.has/.valuemember access and
check maybesemantics are unchanged.Source
Addresses B3. Reproduced against main @ 999a46b:
fun a(x:u64)->Maybe<u64>{return x}failed withTYP003.return Maybe.some(x)failed withNAM003becauseMaybewas not avisible symbol.
Changes
native/zero-c/src/checker.c: recognizeMaybe.some(value)andMaybe.none, type them asMaybe<T>, and add aT -> Maybe<T>coercion in
check_expr_expected(coversEXPR_NUMBERand any otherexpression whose actual type is compatible with
T). A newTYP011message variant fires when
Maybe.nonelacks an explicitMaybe<T>context.native/zero-c/src/ir.c: lowerMaybe.some(literal),Maybe.none,and the
T -> Maybe<T>integer literal coercion to the existingIR_VALUE_MAYBE_SCALAR_LITERAL. No new IR opcodes were added, soevery backend (ELF64, Mach-O, COFF, AArch64 MVP) continues to work
without changes. Non-literal
Maybe.somepayloads and non-scalarelement types fall back to
CGEN004like other MVP gaps.native/zero-c/src/main.c: register azero explain TYP011entrycovering the expanded message.
docs/articles/language-reference.md,docs/articles/diagnostics.md: document the new constructors and therefreshed TYP011 scope.
Conformance
conformance/native/pass/maybe-some.0: build present and absentMaybe via the new constructors and check
.has.conformance/native/pass/maybe-coerce-return.0: function returningMaybe<u8>via plainTandnullcoercion.conformance/native/fail/maybe-bare-without-context.0: bareMaybe.noneis rejected withTYP011.node conformance/run.mjsandnode --experimental-strip-types scripts/snapshot-command-contracts.mtsboth pass locally.
Proposed CHANGELOG line
Maybe.some(value)andMaybe.noneconstructors and accept plainTinMaybe<T>positions.