Skip to content

[soundness] untyped float constants past float64/float32 range pass hyb check at declaration, assignment, return, literal-element, and append sites, then fail go build (issue #228 family D, float leg) #683

Closed

Description

@milkingndb-oss

The smallest .hy program that demonstrates it

package main

import "fmt"

fn main() {
    let y = 1e400
    fmt.println(y)
}

Commit: main @ 0ca08c2. hyb built from that commit (cargo build -p hyb --release, rust 1.99.0). Go 1.26.9.

$ hyb check f32_default.hy
f32_default.hy: OK (0 diagnostics)
$ hyb build f32_default.hy -o f32_default
emitted f32_default.go
go build failed:
# command-line-arguments
f32_default.go:8:7: cannot use 1e400 (untyped float constant 1e+400) as float64 value in assignment (overflows)

Five more sites on the same class, all OK (0 diagnostics) then go build fail (or, for the assignment, fail at the assignment):

// 1. default-float64 local, both spellings
fn main() { y := 1e400 ; fmt.println(y) }        // same error
fn main() { let h = -1e400 ; fmt.println(h) }    // cannot use -1e400 ... (overflows)

// 2. ascribed float32 local
fn main() { var f float32 = 1e40 ; fmt.println(f) }
// f32_default.go:8:18: cannot use 1e40 (untyped float constant 1e+40) as float32 value in variable declaration (overflows)

// 3. reassignment to a float64 binding
fn main() { var y float64 = 1.0 ; y = 1e400 ; fmt.println(y) }
// cannot use 1e400 ... as float64 value in assignment (overflows)

// 4. closure-body local (same default-float64 leg)
fn f() { let y = 1e400 ; fmt.println(y) }

// 5. return statement of a float64 fn
fn f() float64 { return 1e400 }

// 6. slice-literal element / append argument (typed elem float64)
fn main() { let xs = []float64{1e400} ; fmt.println(xs) }
fn main() { let xs = []float64{} ; let ys = append(xs, 1e400) ; fmt.println(ys) }

// 7. past-i128 INTEGER literal at a float-declared site — Go folds the
//    integer constant, converts to the declared float, and rejects past
//    float64's magnitude (`constant overflow`)
fn main() { var x float64 = 1000...0 /* 1 followed by 400 zeros */ ; fmt.println(x) }

What Go accepts at the same sites (controls — the check must NOT reject these):

var x float64 = 1.7976931348623157e308          // f64::MAX, builds
var x float64 = 1.7976931348623158e308          // within half an ulp — rounds down to MAX, builds (go1.26 vet clean)
var x float32 = 3.4028235e38                    // within half an ulp of f32::MAX — rounds down, builds (go1.26 vet clean)
var x float64 = 1e-400                          // underflow rounds to 0 silently in go1.26 — builds, NOT an error
x := 1e308                                      // inside range, builds
let g = 1e308                                   // inside range, builds

What the checker should say

HYB-E6002 (the existing const-overflows-fixed-width code — same guarantee row 13 BUILDABLE class as the integer legs already merged from #228/#148/#201) at every one of the sites above, with the Go diagnostic quoted in the why-note:

  • default-float64 sites (1, 4): constant 1e+400 overflows float64 / cannot use 1e400 (untyped float constant 1e+400) as float64 value in assignment (overflows)
  • ascribed/known-type sites (2, 3, 5, 6): the same with the declared type
  • huge-integer-at-float-site (7): constant overflow

Go's representability rule is rounding-aware (the controls above), so the checker's boundary must be too: an f64 reading of the literal that is non-finite means overflow for float64 targets; for float32 targets the f64→f32 rounding cast being infinite means overflow (this keeps 3.4028235e38 accepted). Underflow is deliberately NOT rejected — go1.26 accepts var x float64 = 1e-400 and var x float32 = 1e-46 (verified with go vet).

What it actually said

OK (0 diagnostics) at every site. hy-emit emits the literal verbatim; the Go compiler rejects it. This is the float leg of the default-typed/declared-typed literal-overflow family (#228 family D): the integer legs already reject via E6002 (let x = <10^48 digits> → overflows default type int), the float legs were never wired.

Claimed severity

P2 - claim-precision bug (accepted value should have been unbuildable)

Related: #576 covered overflow/truncation in binary comparisons, arithmetic, and map indexing — declaration/assignment/return/literal-element/append sites were not in its scope. #670/#671 is const_init (len() folding) — orthogonal.

Activity

  1. added a commit that references this issue on Oct 18, 2026
    89b6370
  2. added 2 commits that reference this issue on Oct 18, 2026
    6ae015c
    9a41d35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions