Repository navigation
Resolve negative indices at run time - #877
Merged
Merged
Conversation
In C++, C#, Java and Go, a negative list index known only at run time was not counted from the back as in Python, and C++ ``xs[-1]`` on an empty list was undefined behavior via ``.back()``. We now route all list and JSON-array indices, literals included, through a per-target helper which resolves a negative index and throws when out of range so that the behavior in all targets is equal to that of Python: * C++: ``common::At(xs, i)``, * C#: ``Common.ListHelpers.At(xs, i)`` and ``SetAt(xs, i, v)``, * Java: ``ListHelpers.at(xs, i)`` and ``ListHelpers.setAt(xs, i, v)``, * Go: ``ourcommon.At(xs, i)`` and ``*ourcommon.PointerAt(xs, i) = v``. Go writes go through a pointer since Go can not infer ``T`` in ``SetAt[T]([]T, int64, T)`` for a ``*Class`` written into an ``[]IClass``. TypeScript ``OurCommon.at`` now throws a ``RangeError`` instead of returning ``undefined``. The helpers are generated only if the meta-model indexes a list. We test reads and writes at negative run-time indices in the common meta-model ``int_length_interplay``.
Coverage Report for CI Build 41426363218Coverage decreased (-0.008%) to 90.341%Details
Uncovered Changes
Coverage Regressions3 previously-covered lines in 2 files lost coverage.
Coverage Stats
💛 - Coveralls |
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.
In C++, C#, Java and Go, a negative list index known only at run time was not counted from the back as in Python, and C++
xs[-1]on an empty list was undefined behavior via.back(). We now route all list and JSON-array indices, literals included, through a per-target helper which resolves a negative index and throws when out of range so that the behavior in all targets is equal to that of Python:common::At(xs, i),Common.ListHelpers.At(xs, i)andSetAt(xs, i, v),ListHelpers.at(xs, i)andListHelpers.setAt(xs, i, v),ourcommon.At(xs, i)and*ourcommon.PointerAt(xs, i) = v.Go writes go through a pointer since Go can not infer
TinSetAt[T]([]T, int64, T)for a*Classwritten into an[]IClass. TypeScriptOurCommon.atnow throws aRangeErrorinstead of returningundefined. The helpers are generated only if the meta-model indexes a list.We test reads and writes at negative run-time indices in the common meta-model
int_length_interplay.