Skip to content

String brackets - #603

Merged
johncbowman merged 3 commits into
masterfrom
stringBrackets
Jul 23, 2026
Merged

String brackets#603
johncbowman merged 3 commits into
masterfrom
stringBrackets

Conversation

@charlesstaats

Copy link
Copy Markdown
Contributor

Access length-one substrings via the notation s[pos], where s is a string and pos is an integer.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class s[pos] indexing support for string, enabling access to length-one substrings via operator[] (including negative indices) and documenting + testing the new behavior.

Changes:

  • Add string.operator[] as a virtual field on the primitive string type, with int key type support for subscripting.
  • Implement the runtime builtin backing stringBrackets (with negative-index handling and out-of-range returning empty string).
  • Add a dedicated test and update the manual to describe s[pos] behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
types.h Adds overrides and a primitiveTy::keyType() override needed for string subscripting.
types.cc Wires operator[] for string as a virtual field and implements primitiveTy::keyType() for string.
runstring.in Implements the runtime thunk/helper used to execute string.operator[].
exp.cc Updates subscript expression type inference to treat string indexing as string.
tests/datastructures/stringBracketsTest.asy Adds coverage for positive/negative/out-of-range indexing and signature checks.
doc/asymptote.texi Documents s[pos] indexing semantics and adds index entries for operator[].

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runstring.in Outdated
Comment thread doc/asymptote.texi Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@johncbowman
johncbowman merged commit e69c2bb into master Jul 23, 2026
11 checks passed
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.

3 participants