Skip to content

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

Closed

Description

@matt-edmondson

What's wrong

#114 made Python and JavaScript truncate integer / (and, in Python, %). The fix depends on a static-type scope, which is opened only in GenerateFunctionDeclaration and GenerateMethod:

  • Coder/Languages/PythonGenerator.cs:424 and :582
  • Coder/Languages/JavaScriptGenerator.cs:330 and :459

Two kinds of body are generated without a scope:

  • Property accessor bodies: PythonGenerator.GeneratePropertyDeclaration / WriteAccessorBody (PythonGenerator.cs:108-175) and JavaScriptGenerator.GeneratePropertyDeclaration / WriteAccessorBody (JavaScriptGenerator.cs:54-95).
  • Entry point bodies: PythonGenerator.GenerateEntryPoint (PythonGenerator.cs:738) and JavaScriptGenerator.GenerateEntryPoint (JavaScriptGenerator.cs:602).

Inside these bodies the setter's value parameter has no known type, and RegisterStaticType does nothing because staticTypeScopes.TryPeek fails, so typed locals are not recorded either. Any / or % on those names falls back to true division and floored modulo.

Reproduction (verified by running the generated output)

  • Property half: int with a setter body that prints value / 2:
    • Python emits print((value / 2)); b.half = 7 prints 3.5.
    • JavaScript emits let h = (value / 2);, which gives 3.5.
  • EntryPoint with body int a = 7; int q = a / 2;:
    • Python emits q = (a / 2) → 3.5.
    • JavaScript emits let q = (a / 2); → 3.5.
  • Every C-family target gives 3 in both cases.

Suggested fix / acceptance criteria

  • Open a static-type scope around each accessor body: the setter's scope holds value typed as the property's Type; the getter's scope has the property's type as its return type. The entry point also needs a scope so typed locals are tracked. One option is an OpenStaticTypeScope overload taking a parameter map and return type alongside the FunctionDeclaration one.
  • Add IntegerDivisionTests cases that run a setter, a getter local and an entry-point local under Python and Node, including negative operands.
  • Related: Compound /= and %= give different results in Python and JavaScript: a /= 2 makes an int 2.5 (not covered by #114) #183 covers compound /= and %=, which is a separate path.

Activity

  1. added
    bug
    on Oct 7, 2026
  2. matt-edmondson commented on Oct 7, 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