Skip to content

Python and JavaScript leave a field with no initialiser unset: self.count += 1 raises AttributeError, and JS produces NaN #345

Closed

Description

@matt-edmondson

What's wrong

The contract (CLAUDE.md:63, Coder/Ast/FieldDeclaration.cs:10-15) is that a field with no initialiser is value-initialised, so a default-constructed instance is the one the declaration describes. C++ writes int count{};, C# and Go start at zero, and Rust uses Default.

Python and JavaScript don't follow it:

  • Python fields: PythonGenerator.GenerateFieldDeclaration (Coder/Languages/PythonGenerator.cs:474-503) writes a bare annotation, count: int. That creates no attribute. The remark there cites dataclasses, but no @dataclass is ever emitted, and CLAUDE.md explicitly declines it.
  • Python auto-properties: these are written as Size: int = None (:131-134).
  • JavaScript: writes count;, which is undefined (JavaScriptGenerator.cs:359).

Repro

Take a class Counter { count: int; step: int = 1 } with a constructor and a next() method that does count += step; return count;.

  • In Python, Counter().next() raises AttributeError: 'Counter' object has no attribute 'count'.
  • In JavaScript, new Counter().count + 1 is NaN.
  • In Python, an int auto-property reads as None.

Suggested fix / acceptance criteria

Related: #132 and #178 (closed) are different cases.

Activity

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