Skip to content

self.p / 2 on an int auto-property returns 3.5 in Python and JS, and self.p + 1L fails to compile in Rust: property reads have no static type #466

Open

Description

@matt-edmondson

What's wrong

#433 made a member read such as self.total carry its field's declared type, so integer arithmetic on it is lowered correctly. The lookup behind that fix does not consider properties:

  • DeclaredFieldType (Coder/Languages/StandardLanguageGenerator.cs:625-650, reached through DottedMemberType at :574) matches only FieldDeclaration and VariableDeclaration members of the class.
  • DeclaredMemberType (:807-830) has the same gap.

An automatic PropertyDeclaration is lowered to a plain field in every target. Separated rewrites it only in the member list it writes out, while these lookups read the original classDecl.Members, where the member is still a PropertyDeclaration. Its reads therefore have no known type, and every StaticType-driven lowering is skipped for them.

Reproduction (HEAD 60ace00)

class Acc has three int members: a FieldDeclaration f, an automatic PropertyDeclaration p (HasSetter = true, no accessor bodies) and a VariableDeclaration v. Each has a method int half_X() returning BinaryExpression(VariableReference("self.X"), Divide, Literal<int>(2)), written this.X for JS.

Target f and v p
Python self.f // 2 if ... else -(-self.f // 2), so 7 gives 3 return (self.p / 2), so 7 gives 3.5 (executed)
JavaScript Math.trunc((this.f / 2)), so 7 gives 3 return (this.p / 2), so 7 gives 3.5 (executed)
Rust, long wide_X() => self.X + 1L (self.f as i64) + 1, which compiles (self.p + 1): rustc E0308 mismatched types, i32 vs i64

% on p is also wrong in Python, which floors it.

Why it matters

An AST that declares state as an automatic property, which is the normal C# shape, gets silently wrong arithmetic in Python and JS and a compile error in Rust. The same AST with a field is correct. That is exactly the class of bug #433 closed, still open for properties.

Suggested fix

Activity

  1. matt-edmondson commented on Nov 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

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions