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
Compound /= and %= give different results in Python and JavaScript: a /= 2 makes an int 2.5 (not covered by #114) #183
#114 covers BinaryExpression with BinaryOperator.Divide and BinaryOperator.Modulo. Compound assignment takes a separate code path that #114 does not mention.
LanguageGeneratorBase.GenerateAssignmentStatement (Coder/Languages/LanguageGeneratorBase.cs) emits target <op>= value using GetAssignmentOperator(assignment.Operator) for every target. Neither PythonGenerator nor JavaScriptGenerator overrides it; only GoGenerator does, for an unrelated reason. So a fix that only changes how BinaryExpression is spelled will leave this path unchanged.
Repro
Use new AssignmentStatement(new VariableReference("a"), new LiteralExpression<int>(2), AssignmentOperator.DivideAssign) on an int a = 5.
Target
Emitted
a afterwards
C, C++, C#, Go, Rust
a /= 2
2
Python
a /= 2
2.5 (a float, in a function annotated -> int)
JavaScript
a /= 2
2.5
%= diverges for negative operands. With a = -7, a %= 2 gives 1 in Python, which floors, and -1 in the C family.
Category: Bug (the same AST behaves differently across targets)
Priority: Medium. The output compiles and runs, but integer /= gives 2.5 in Python and JavaScript, and %= with a negative operand differs in Python. Nothing warns about it.
Area / suggested owner:LanguageGeneratorBase.GenerateAssignmentStatement, and the Python and JavaScript generators.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
/=gives2.5in Python and JavaScript, and%=with a negative operand differs in Python. Nothing warns about it.LanguageGeneratorBase.GenerateAssignmentStatement, and the Python and JavaScript generators.-7 / 2returns -3 in C/C++/C#/Go/Rust but -3.5 in Python and JS #114 and should land together with it, reusing Integer division and modulo give different results in Python and JavaScript:-7 / 2returns -3 in C/C++/C#/Go/Rust but -3.5 in Python and JS #114's lowering helper. No open PR covers it.Generated by Claude Code