Skip to content

Improve distinct borrow matching and add tests#13

Merged
Clemente90 merged 5 commits intodevelfrom
codex/fix-tdd-test-and-update-borrow-pragmas
Jan 21, 2026
Merged

Improve distinct borrow matching and add tests#13
Clemente90 merged 5 commits intodevelfrom
codex/fix-tdd-test-and-update-borrow-pragmas

Conversation

@Clemente90
Copy link
Owner

Motivation

  • Borrow resolution produced incorrect matches, crashes and unintended instantiations for nested distinct and generic types; normalizing/peeling those wrappers and avoiding instantiation during borrow lookup is required.

Description

  • Introduced guarded normalization and unwrapping helpers (normalizeBorrowType, baseTypeFromDistinctGeneric, borrowSearchType) and a scoring matcher borrowMatchScore to preference best overloads when resolving borrows, and integrated them into searchForBorrowProc (compiler/semcall.nim).
  • Avoided recursive/erroneous instantiation during borrow resolution by adding the inBorrowSearch context guard and using borrowInstType to compare types without triggering generic instantiation (compiler/seminst.nim, compiler/semdata.nim).
  • Adjusted distinct-base collapsing and generic-instantiation handling so nested distinct/generic wrappers are collapsed safely when computing borrow compatibility (compiler/seminst.nim, compiler/semcall.nim).
  • Added focused tests exercising nested distinct/generic borrow edge cases: tests/distinct/tborrow_nested_distinct_len.nim, tborrow_static_array_nested.nim, tborrow_ref_object.nim, and tborrow_string_concat.nim.

Testing

  • Built the compiler and ran focused compiles of the new tests with bin/nim c -d:release -r compiler/nim c -d:release -r tests/distinct/tborrow_nested_distinct_len.nim, .../tborrow_static_array_nested.nim, .../tborrow_ref_object.nim, and .../tborrow_string_concat.nim, all of which completed successfully.
  • Ran the distinct test suite with bin/testament --nim:compiler/nim c tests/distinct, which reported 24 passed and 1 failure; the lone failure is a JS-backend invocation failing because the compiler binary in this environment was not built with the JS backend, not a regression introduced by these changes.

Codex Task

@Clemente90 Clemente90 merged commit ad9ddd5 into devel Jan 21, 2026
@Clemente90 Clemente90 deleted the codex/fix-tdd-test-and-update-borrow-pragmas branch January 21, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant