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
constant that overflows its declared fixed-width type is accepted, emitted Go fails: cannot use 300 as int8 value (overflows) #148
A narrowing constant assignment passes hyb check (0 diagnostics) and the emitted Go cannot be built: overflows.
fn main() {
var n int8 = 300
fmt.println("{n}")
}
$ hyb check f.hy
f.hy: OK (0 diagnostics)
$ hyb build f.hy --emit-go && go vet ./...
./a.out.go:8:15: cannot use 300 (untyped int constant) as int8 value in variable declaration (overflows)
The conversion form is unaffected when its operand is a variable — that is the runtime truncation path and it works correctly:
fn main() {
x :=300
y := byte(x) // ok: runtime truncation
fmt.println("{y}") // 44
}
So the checker treats the two shapes differently in Go's eyes but identically in its own: a constant initializer that cannot fit the declared type is a compile error in Go, and nothing in hyb check notices.
Searched for duplicates
repo:limitlessprojects/Go-Hybrid overflow → 0 hits. No issue or PR mentions constant-overflow at a declared type.
Suggested fix
Two options, both consistent with existing behaviour:
Checker diagnostic (preferred): when a local's declared type is a fixed-width numeric and its initializer is a constant literal, range-check the literal against the type and report a new code (HYB-E3xxx). This matches how the checker already reasons about the declared contract rather than the emitted Go.
Emitter refusal in the same shape as unbound_crate_call_refused_honestly (an honest "this cannot be represented" message rather than an emission that dies later).
Option 1 gives the author the diagnostic they need at the point of the mistake.
Environment
Commit f99d6d0 (main at the time of writing), Go 1.26.9 (the pinned version).
Activity
emit: translate the SPEC primitive type names, and fold constant conv…
fix(hy-check): reject constant init outside fixed-width declared type…
Merge pr-163 (salvocanci, fixes limitlessprojects#148): a constant th…
fix(hy-check): reject invalid builtin args and defer non-calls (#187)
Merge pr-191 (salvocanci, fixes #187): defer non-call (E2001) + built…
fix(hy-check): reject constant overflow in assignments and compound a…
fix(hy-check): reject constant overflow in assignments and compound a…
Merge pr-703 (dezzy-music, fixes #683): reject untyped float constant…