Repository navigation
Type a call by its declared callee so Python and JavaScript truncate twice(a) / 4 [patch] - #276
Merged
Merged
Conversation
…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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #273
What changed
StandardLanguageGenerator.StaticTypehad noCallExpressioncase, so a call's result was of unknown type. Python and JavaScript then fell back to true division (and Python's floored%). Sotwice(a) / 4gave-3.5fora = -7, where C, C++, C#, Go and Rust give-3. This happened even withtwicedeclaredintin the same file.ReturnTypeof the oneFunctionDeclarationin the tree being generated (GenerationRoot) that has its name.ExpectedTypestill 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
CallResultIntegerDivisionTestscovers this.int twice(int a)is executed. For/and%,twice(a)is divided once into a typed local and once in a return. With theStaticTypechange reverted, Python reportshalf_local(-7) = -3.5, expected -3.twiceand an undeclaredelsewherestill produce true division.Generated by Claude Code