Skip to content

Compound /= and %= give different results in Python and JavaScript: a /= 2 makes an int 2.5 (not covered by #114) #183

Closed

Description

@matt-edmondson

What's wrong

#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.

Suggested fix / acceptance criteria

Depends on / should be done with: #114.

Activity

  1. added
    bug
    on Oct 6, 2026
  2. matt-edmondson commented on Oct 6, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions