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
Python and JavaScript use true division on a call result: twice(a) / 4 gives -3.5 where the other targets give -3 #273
The integer-division fix (#114, #183, #191) only applies when StandardLanguageGenerator.IsIntegerArithmetic can prove both operands are integers (Coder/Languages/StandardLanguageGenerator.cs ~L166-L170).
StaticType(Expression) (~L321-L370) has no CallExpression case, so the type of any call result is unknown. The Python and JavaScript division overrides then fall back to true division (PythonGenerator.cs ~L1048, JavaScriptGenerator.cs ~L761). This happens even when:
the callee is a sibling FunctionDeclaration in the same file that declares ReturnType = "int", and
the result is assigned to a local declared int, or returned from a function declared int.
Reproduction
int twice(int a) { return a * 2; }
int half(int a) { int t = twice(a); t = twice(a) / 4; return t; }
// entry point prints half(-7)
Target
Generated
half(-7)
C#, C, C++, Go, Rust
twice(a) / 4
-3
Python
t = (twice(a) / 4)
-3.5, stored in a local annotated int
JavaScript
t = (twice(a) / 4); with no Math.trunc
-3.5
The program compiles in every target, so nothing flags the wrong value.
This is in the same family as #267, where a unary expression loses its static type. The cause and fix here are separate: a call, not a unary operator.
Suggested fix
Add a CallExpression case to StaticType:
If the call has an ExpectedType, use it. This is already how the code behaves, and setting it is the only workaround today.
Otherwise, for a call with no receiver, resolve Callee against the FunctionDeclarations in the enclosing SourceFile, namespace or class. When exactly one function matches, return its ReturnType.
Acceptance criteria
In Python and JavaScript, twice(a) / 4 truncates exactly as a / 4 does when twice is declared int.
% follows the same rule.
A call to an unknown or overloaded callee keeps today's behaviour.
Regression tests are added to the existing Python and JavaScript generator tests.
Priority: High. The output compiles in every target but Python and JavaScript compute a different value (-3.5 vs -3), and an int-annotated Python local silently holds a float. Wrong results with no diagnostic are worse than a build failure.
Area / suggested assignee:StandardLanguageGenerator.StaticType (no CallExpression case), which feeds IsIntegerArithmetic and the Python/JavaScript division overrides. Owner: @matt-edmondson
Activity
matt-edmondson commentedon Oct 19, 2026
Triage
int-annotated Python local silently holds a float. Wrong results with no diagnostic are worse than a build failure.StandardLanguageGenerator.StaticType(noCallExpressioncase), which feedsIsIntegerArithmeticand the Python/JavaScript division overrides. Owner: @matt-edmondson-7 / 2returns -3 in C/C++/C#/Go/Rust but -3.5 in Python and JS #114, Compound/=and%=give different results in Python and JavaScript:a /= 2makes an int 2.5 (not covered by #114) #183, Integer division in a property accessor or entry point body still gives 3.5 in Python and JavaScript (#114 only covers functions and methods) #191, all closed) and is a sibling of A unary expression loses its static type: C writesvoid* b = (-a);, Go types-(1.5f)as float64, and Python/JS do true division on-a / 2#267 (unary expressions lose their static type). Open PRs Map fixed-width integer types and apply variable member defaults in constructors #266 and Derive Clone, Copy, Debug, PartialEq, Eq and Hash on Rust enums [patch] #263 don't touchStaticType.CallExpressioncase (useExpectedType, else resolve a receiver-less callee to a single siblingFunctionDeclaration'sReturnType), and cover/and%in the Python and JavaScript generator tests. Worth landing alongside A unary expression loses its static type: C writesvoid* b = (-a);, Go types-(1.5f)as float64, and Python/JS do true division on-a / 2#267, since both extend the same switch.Generated by Claude Code