Skip to content

D181: an integer beside a float is the float (§4.2.6) - #2919

Merged
ehartford merged 1 commit into
mainfrom
d181-int-to-float
Nov 2, 2026
Merged

ehartford merged 1 commit into
mainfrom
d181-int-to-float

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Eric, on let p = i / 140.0 being refused: "dividing an integer by a
float should be a float." Integer-to-float conversion is implicit in
arithmetic, comparison and where a float is demanded; the result of mixed
arithmetic is the float; float-to-integer stays explicit (as truncates,
.round() as rounds).

  • Sema: implicit_numeric_join returns the float for an integer-and-float
    pair, so arithmetic and comparison take it from one place; a float
    demand accepts an integer value. The two "no implicit integer-to-float
    conversion" diagnostics are gone.
  • Codegen: a store into a float destination converts an integer with its
    source's signedness (mir_coerce_value_to_sema_type; the array-literal
    element and union-field stores pass it); coerce_value_to_type has the
    signed default. The operation path already converted.
  • §4.2.6 states the rule (wording for Eric to bless); the decision log
    has D181; the two Sema: implicit integer narrowing is diagnosed only for an annotated let; sequence/tuple/struct literal elements, call arguments, return values and global initializers narrow silently #1803 fixtures that pinned the refusal became
    behav_d181_int_beside_float_is_float.w (division, multiplication, a
    typed element, u32 and i32 into floats, a comparison, an argument).

Eric, on `let p = i / 140.0` being refused: "dividing an integer by a
float should be a float." Integer-to-float conversion is implicit in
arithmetic, comparison and where a float is demanded; the result of mixed
arithmetic is the float; float-to-integer stays explicit (`as` truncates,
`.round() as` rounds).

- Sema: implicit_numeric_join returns the float for an integer-and-float
  pair, so arithmetic and comparison take it from one place; a float
  demand accepts an integer value. The two "no implicit integer-to-float
  conversion" diagnostics are gone.
- Codegen: a store into a float destination converts an integer with its
  source's signedness (mir_coerce_value_to_sema_type; the array-literal
  element and union-field stores pass it); coerce_value_to_type has the
  signed default. The operation path already converted.
- §4.2.6 states the rule (wording for Eric to bless); the decision log
  has D181; the two #1803 fixtures that pinned the refusal became
  behav_d181_int_beside_float_is_float.w (division, multiplication, a
  typed element, u32 and i32 into floats, a comparison, an argument).
@ehartford
ehartford marked this pull request as ready for review November 2, 2026 02:46
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on e6489bc (seed-driven, tools/battery.w); gate green before it. The §4.2.6 wording and the D181 entry are drafted for Eric's blessing.

@ehartford
ehartford merged commit 4464267 into main Nov 2, 2026
@ehartford
ehartford deleted the d181-int-to-float branch November 2, 2026 13:24
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.

1 participant