Fix distinct borrow handling for bracket operators and restrict type-level borrow pragma to .#9
Merged
Clemente90 merged 3 commits intodevelfrom Jan 19, 2026
Conversation
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.
Motivation
[]in the distinct type-level{.borrow.}pragma and introduced regressions in bracket-operator borrowing for builtin-like containers; the language manual limits type-level borrow to dot only and bracket operators must be borrowed via procs.{.borrow.}for magic bracket ops (array/seq/openArray/etc.) across multiple distinct types, generic instantiations and block scopes without creating global ambiguities.Description
.and emit a clear error for attempts to use[]in type declarations by updatingcompiler/pragmas.nim.tfBorrowBracketspropagation and ensure[].borrows are handled via proc-level logic incompiler/semstmts.nim,compiler/semexprs.nimandcompiler/semcall.nim.compiler/semcall.nimandcompiler/sigmatch.nim.[]proc parameters, includingtyGenericInvocationcases, viacompiler/semstmts.nimadjustments.compiler/astdef.nim,compiler/ic/enum2nif.nim) and rework the semantic subscript handling to respect borrow flags incompiler/semexprs.nim.tests/distinct/tborrow_type_pragma_brackets.nim, addtests/distinct/tborrow_seq_brackets.nim, and update severaltests/distinct/*files to use proc-level{.borrow.}for brackets and exercise multiple distinct types, generics and block-scope cases.Testing
./bin/nim c ... kochand./koch bootand the build succeeded../bin/nim r tests/distinct/tborrow_array_brackets.nim,./bin/nim r tests/distinct/tborrow_negative_generics_and_blockscope.nim, and./bin/nim r tests/distinct/tborrow_seq_brackets.nim, all of which executed successfully../bin/nim check --hints:off --warnings:off tests/distinct/tinvalidborrow.nimand it produced the expected reject diagnostics.Codex Task