Repository navigation
D103: a value converts to Option[T] where one is demanded (§4.9a) - #2224
Merged
Merged
Conversation
Where a concrete `Option[T]` is demanded and the expression has type `T`, Sema records the node in `value_to_option_nodes` once, at the demand (`check_expr_with_expected`), and MIR builds the `Some` around the lowered value. The node keeps its own type; the record is the conversion. `None` and an existing Option pass unchanged; `Option[Option[T]]` from a bare `T` is refused (once); a generic `Option[T]` demand never fires (no inference); an operator's operands are marked in `operator_operand_nodes` at `check_binary_operator` and never convert, so `opt == 3` stays an error. The demand propagates into the payload: `option_demand_payload` peels a concrete `Option[T]` to `T` for an untyped literal's context type and for a named fn's expected callable type, so `g(twice)` takes the `extern "C" fn` type and `let x: Option[i64] = -7` is an i64 literal. A value Sema admitted by lossless widening (`i32` into `Option[i64]`) is cast to the payload before the aggregate. The typed MIR validator was silent over that aggregate (an `i32` operand stored into an `i64` payload read back right by luck): `mir_validate_aggregate_scalar_mismatch` now refuses a scalar payload operand of another width, signedness or kind, with a hand-built MIR test. `lib/std/regex.w` drops the `Some(...)` ceremony around its allocator callbacks. Fixes #2217.
Contributor
Author
|
Battery GREEN on 2fb6385 (seed-driven, |
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.
Implements §4.9a (D103, PR #2221): where a concrete
Option[T]is demanded and the expression has typeT, it isSome(expression)— once, at the demand, never in inference; demand propagates into arms, tails and the payload (a named fn takesextern "C" fn, a literal takesi64); an operator's operands are not demand sites.Also: the typed MIR validator now refuses an enum payload operand that is a scalar of another width/signedness/kind than the variant's payload (it was silent over
Option[i64].Some(i32)), andlib/std/regex.wdrops itsSome(...)ceremony.Fixes #2217.
Draft until the battery is green.