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
Go maps the AST's int to Go's 64-bit int, so shifts and overflow give different values than every other target #422
Coder/Languages/GoGenerator.cs:139 maps { "int", "int" }. Go's int is 64 bits on every platform Go targets in practice, so a Go int is not the AST's int. Every other generator treats int as 32 bits:
C# int
C/C++ int
Rust i32 (RustGenerator.cs:71)
The Go table is also inconsistent with itself: uint → uint32, short → int16 and long → int64 all name an explicit width, and only int does not.
Failure scenario
The AST int wrap(int x) { return (x << 31) >> 31; } is emitted as:
funcwrap(xint) int { return ((x<<31) >>31) }
wrap(1) prints 1 under go run. The same AST gives -1 in C#, C (gcc), C++ (g++), Rust and JavaScript. Overflow differs the same way: int.MaxValue + 1 wraps to int.MinValue everywhere except Go, where it becomes 2147483648. Both programs compile, so the Go output computes a different value with no error.
Suggested fix / acceptance criteria
Map int to int32 in the Go type table.
Check that the generator's existing mixed-width conversion logic (the code that already handles int16/uint32/int64 operands) inserts the conversions now needed where an int32 meets an untyped constant, a len(...) result or an index expression. Examples: slice indexing and len return Go int, so int32(len(xs)) / xs[int(i)] may be required.
Add a test that (x << 31) >> 31 with x = 1 evaluates to -1 in the Go output, and a test for int.MaxValue + 1 wrapping.
Related but distinct: #362 (shift typed as the wider operand).
Priority: High. The Go output compiles and silently computes different values from every other target for shifts and overflow on int. That breaks the cross-language equivalence the generator is built around, and nothing warns the user. The one-line table change has a large blast radius: len(...), indexing and untyped constants will need conversions once int means int32. Expect follow-up breakage in existing Go tests.
Area / suggested owner: Go generator (Coder/Languages/GoGenerator.cs type table around line 139, and its mixed-width conversion logic).
Activity
matt-edmondson commentedon Oct 31, 2026
Triage
int. That breaks the cross-language equivalence the generator is built around, and nothing warns the user. The one-line table change has a large blast radius:len(...), indexing and untyped constants will need conversions onceintmeansint32. Expect follow-up breakage in existing Go tests.Coder/Languages/GoGenerator.cstype table around line 139, and its mixed-width conversion logic).int < uint#374 (mixed narrow/unsigned arithmetic in Go/Rust), A conditional whose branches have different numeric types (c ? 1 : 2.5,c ? intVar : longVar) fails to compile in Rust and Go #375 and Go: a conditional's condition skips operand widening, son < limit ? … : …with int and long (orx > 0.5on an int) fails to compile #395 (Go numeric widening in conditionals). Those concern compile failures, and this one concerns wrong values. It touches the same conversion code, so coordinate the fixes. No open Coder PR changes Go'sintmapping.Generated by Claude Code