Skip to content

Enable borrowed methods on distinct types#18

Merged
Clemente90 merged 2 commits intodevelfrom
codex/improve-readability-and-comments-in-tests-0io3b5
Jan 22, 2026
Merged

Enable borrowed methods on distinct types#18
Clemente90 merged 2 commits intodevelfrom
codex/improve-readability-and-comments-in-tests-0io3b5

Conversation

@Clemente90
Copy link
Owner

Motivation

  • Allow method declarations to be borrowed on distinct wrapper types so distinct wrappers can forward method overloads and preserve dynamic dispatch and UFCS behavior.
  • Update the distinct-subclass test to exercise borrowing method directly instead of asserting the compiler rejects it.

Description

  • Updated tests/distinct/tborrow_subclass_methods.nim to declare the subclass kind methods as borrowed (.borrow.) for DistinctAnimal, DistinctDog and DistinctDog2 and adjusted several related test values.
  • Unwrapped distinct parameter types when checking whether a routine has an object parameter by changing hasObjParam to accept a PContext and repeatedly calling baseOfDistinct so borrowed methods on distinct wrappers are recognized as object methods.
  • Ensure borrowed routines that have return types get a proper result symbol by introducing addResult usage and invoking it when constructing borrowed bodies (semBorrow) and related code paths so codegen has a valid result slot.
  • Avoid generating method prototypes/dispatchers for borrowed method declarations by skipping semMethodPrototype/dispatcher creation when sfBorrow is present, preventing incorrect dispatcher generation for borrowed methods.
  • Minor AST/result-slot fixups when copying/constructing borrowed symbols so prototypes and dispatchers aren't left with nkEmpty result nodes.

Testing

  • Built the compiler with bin/nim c --skipUserCfg --skipParentCfg --hints:off -d:release -o:bin/nim compiler/nim.nim (succeeded).
  • Built testament with bin/nim cc --opt:speed -o:testament/testament testament/testament.nim (succeeded).
  • Ran the distinct test category with ./testament/testament --nim:bin/nim cat distinct --hints:off and all tests in the distinct category passed.

Codex Task

@Clemente90 Clemente90 marked this pull request as ready for review January 22, 2026 20:33
@Clemente90 Clemente90 merged commit df41519 into devel Jan 22, 2026
@Clemente90 Clemente90 deleted the codex/improve-readability-and-comments-in-tests-0io3b5 branch January 22, 2026 20:33
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