Repository navigation
Store SubTree literals as strings again; numeric strings work in script arithmetic (#1246) - #1254
Merged
Merged
Conversation
…ript arithmetic (#1246) Since #1121 (shipped in 4.9.1), a numeric literal passed to a SubTree port was stored as int/int64_t/double. That locked the entry type, so the same value could no longer be read by a std::string port (tree creation failed), custom convertFromString<T> was bypassed, and the spelling was lost ("007" became 7). Literals are stored as strings again. The goal of #1121, arithmetic on numeric literals in Script, is kept by the script evaluator instead: in + - * /, a string operand mixed with a number is converted when the whole string is a number (integer first, then double). Behavior change compared to 4.9.1 - 4.10.0, back to pre-4.9.1 behavior: two literal operands are strings ("1" + "2" is "12", "10" < "2" compares text), and compound assignment, unary minus, bitwise and logic operators on such a literal require an explicit number again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 #1246.
Problem
Since #1121 (first released in 4.9.1), a numeric literal passed to a SubTree, e.g.
<SubTree ID="Sub" mode="1"/>, is stored in the child blackboard asint/int64_t/doubleinstead ofstd::string. That locks the entry type, so:std::stringport: tree creation fails with "port [mode] was initially created with type [int] and, later type [std::string] was used";doubleport reading"1"fails the same way, and customconvertFromString<T>parsing is bypassed;"007"becomes7,"1e3"becomes1000).Fix
xml_parsing.cpp: literals are stored as strings again, as before 4.9.1. Each port converts the text to its own type.scripting/operators.hpp: the goal of Preserve numeric types for literal subtree port values #1121 (arithmetic on numeric literals in Script) moves into the evaluator. In+ - * /, a string operand mixed with a number is converted if the whole string is a number (integer first, thenparseDoublewith full consumption, the same grammar Preserve numeric types for literal subtree port values #1121 used)."42abc","true"and" 42"are rejected, so"text" + 1still throws. String+string,.., comparisons, bitwise and logic operators are unchanged.The #1121 test
SubTree.LiteralNumericPortsPreserveTypeis kept unchanged and passes.Behavior change
Compared to 4.9.1 – 4.10.0, these go back to pre-4.9.1 behavior:
a + bwitha="1" b="2"gives"12", anda < bwitha="10" b="2"compares text;int_val += 1,-int_val,int_val & 1,int_val && 1and a bare<Precondition if="int_val">on such a literal need an explicit number again.No API/ABI change: only the inline evaluator in a public header and a
.cppchange.Tests
SubTree.LiteralPortsAreReadByAnyPortType: the issue's case.mode="1"is read by string, int and double ports, andcode="007"keeps its spelling.ParserTest.NumericStringArithmetic: both operand orders, rejected strings, string+string concatenation unchanged.Both new tests fail on master and pass with the fix. Full suite: 574 passed.
🤖 Generated with Claude Code