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
Python/JavaScript do true division on a file-scope int field (LIMIT / 2 gives -3.5, C gives -3), and C types a local copied from it as void* #304
StandardLanguageGenerator.StaticType (Coder/Languages/StandardLanguageGenerator.cs:322-372) resolves a VariableReference only through staticTypeScopes (:361-370). Those scopes hold only a function's parameters and locals (PushStaticTypeScope, :82-95; RegisterStaticType, :287). A FieldDeclaration at file or namespace scope is never registered, so a bare reference to it has no static type, even though its Type is declared right alongside.
Python's and JavaScript's integer-division overrides depend on StaticType, so they fall back to true division. C's inferred-local typing depends on it too and falls back to void*. This is the same family as #273 (fixed for calls in 6284a3f), but field reads still fall through this gap.
Python: return (LIMIT / 2), so half() returns -3.5
JavaScript: return (LIMIT / 2);, so half() returns -3.5
C / C# / C++ / Go / Rust: -3
C: void* k = LIMIT;. gcc 13 warns -Wint-conversion; gcc 14+ rejects it, since int-conversion is an error by default there.
Suggested fix
When StaticType resolves a VariableReference that no function scope declares, look it up among the FieldDeclarations (and file-scope VariableDeclarations) visible from GenerationRoot, the same way DeclaredReturnType (:388-400) resolves a callee. Resolve only when exactly one declaration has the name.
Acceptance criteria
LIMIT / 2 and LIMIT % 2 with an int file-scope field truncate in Python and JavaScript (-3 and -1 for -7).
An inferred local initialised from an int field is written int k in C (and in C++ if affected).
A name declared by more than one field, or shadowed by a parameter or local, keeps today's behaviour, with the parameter or local winning.
Priority: High. The generated Python and JavaScript compile and run but silently return different numbers from the other targets (-3.5 vs -3). For a cross-language code generator, that is worse than a compile error. C output is also rejected outright by gcc 14+.
Area / suggested assignee:StandardLanguageGenerator.StaticType (Coder/Languages/StandardLanguageGenerator.cs:322-372) and the static-type scopes (:82-95, :287). Owner: @matt-edmondson
Next step: resolve an otherwise unscoped VariableReference against the unique FieldDeclaration (or file-scope VariableDeclaration) visible from GenerationRoot, the way DeclaredReturnType resolves callees, and let parameters and locals win. Add the LIMIT / 2, LIMIT % 2 and inferred-local cases from the issue.
Activity
matt-edmondson commentedon Oct 20, 2026
Triage
StandardLanguageGenerator.StaticType(Coder/Languages/StandardLanguageGenerator.cs:322-372) and the static-type scopes (:82-95,:287). Owner: @matt-edmondsonStaticTypearea, so coordinate with it to avoid a conflict. Neither covers file-scope fields.VariableReferenceagainst the uniqueFieldDeclaration(or file-scopeVariableDeclaration) visible fromGenerationRoot, the wayDeclaredReturnTyperesolves callees, and let parameters and locals win. Add theLIMIT / 2,LIMIT % 2and inferred-local cases from the issue.Generated by Claude Code