Skip to content

Type a call by its declared callee so Python and JavaScript truncate twice(a) / 4 [patch] - #276

Merged
matt-edmondson merged 2 commits into
mainfrom
claude/coder-273-call-result-static-type
Oct 19, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
claude/coder-273-call-result-static-type

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #273

What changed

StandardLanguageGenerator.StaticType had no CallExpression case, so a call's result was of unknown type. Python and JavaScript then fell back to true division (and Python's floored %). So twice(a) / 4 gave -3.5 for a = -7, where C, C++, C#, Go and Rust give -3. This happened even with twice declared int in the same file.

  • A receiver-less call now takes the ReturnType of the one FunctionDeclaration in the tree being generated (GenerationRoot) that has its name.
  • If no function in the tree has that name, or more than one does (overloads, or a namesake elsewhere), the type stays unknown and today's behaviour is unchanged.
  • An explicit ExpectedType still wins, as before.

Resolution is by unique name across the generated tree, not by enclosing scope, because AST nodes carry no parent link. A namesake anywhere in the tree turns resolution off rather than risking the wrong type.

Tests

New file CallResultIntegerDivisionTests covers this.

  • Python and JavaScript, run for real: the generated output for a file with int twice(int a) is executed. For / and %, twice(a) is divided once into a typed local and once in a return. With the StaticType change reverted, Python reports half_local(-7) = -3.5, expected -3.
  • Unchanged cases: an overloaded twice and an undeclared elsewhere still produce true division.
  • The full suite passes: 1319/1319.

Generated by Claude Code

…twice(a) / 4 [patch]

StaticType had no CallExpression case, so a call's result was of unknown
type and the Python and JavaScript division and remainder overrides fell
back to true division and flooring: `twice(a) / 4` gave -3.5 for a = -7
where the C family gives -3, even with `twice` declared `int` beside it.

A receiver-less call now takes the return type of the one
FunctionDeclaration in the tree being generated that has its name. A
callee declared nowhere in the tree, or by more than one function, stays
unknown, which keeps today's behaviour. An ExpectedType still wins.

Fixes #273

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CFV1ukfTLyVhjxAWRuEzGD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CFV1ukfTLyVhjxAWRuEzGD
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit a94467e into main Oct 19, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the claude/coder-273-call-result-static-type branch October 19, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python and JavaScript use true division on a call result: twice(a) / 4 gives -3.5 where the other targets give -3

2 participants