Skip to content

Word30210/fix trait#10

Merged
Word30210 merged 2 commits into
mainfrom
word30210/fix-trait
May 18, 2026
Merged

Word30210/fix trait#10
Word30210 merged 2 commits into
mainfrom
word30210/fix-trait

Conversation

@Word30210
Copy link
Copy Markdown
Contributor

What

  • Introduce trait.inherent(class_table, methods): C & M for merging a class's own methods (kept in a separate table) into the class table; methods already present are not overwritten.
  • Add brief doc comments above Trait<D>, define, impl, and inherent in src/std/trait/init.luau.
  • Update tests/std/trait/.check.luau to express the new convention — own methods live in a dedicated table and are merged via inherent — and demonstrate that inherent's C & M return surfaces those methods at the type level.
  • Add three focused .inherent cases to tests/std/trait/.spec.luau (copies own methods / returns the class table / does not overwrite an existing method) and reshape the integration case to follow the new convention.

Why

#8 documents the limitation of the previous convention. To silence the duplicate-method ambiguity that arises when an implementer's class table and a trait's Requires<Self> both contribute the same method into the final intersection, __index had to be widened with __index = Class :: {}. That cast erased the class table's type from typeof(Prototype), so any method the class defined for itself — one not required by any trait — became invisible on instances even though it existed at runtime.

trait.inherent carves own methods out into a separate, dedicated table whose type is captured by inherent's C & M return (and remains directly available as typeof(methods_table)). With own methods isolated from the trait-required surface, implementers can compose their public instance type from independent pieces — class fields, the metatable, the own-methods table, and each Trait.For<Self> — without forcing the duplicate-method intersection that motivated the :: {} workaround in the first place. define and impl are unchanged; the addition is purely additive.

Closes #8.

Checklist

Required

  • lute run ./scripts/checker.luau -- ./src ./tests ./scripts passes
  • lute run ./scripts/tester.luau passes
  • I linked the related issue if one exists (for example: Closes #19)

Functional Validation

  • Tests cover the changed behavior (.spec.luau and/or .check.luau added or updated)
  • Both happy and edge paths verified where applicable

Configuration & Docs

  • User-facing docs were updated where applicable (README.md / README.ko.md / CLAUDE.md)
  • New dependencies / configuration are reflected in pesde.toml / mise.toml
  • No sensitive values or credentials were introduced

If Applicable

  • Breaking type-surface or API changes are clearly described in this PR

@Word30210 Word30210 merged commit 72f6bfe into main May 18, 2026
2 checks passed
@Word30210 Word30210 deleted the word30210/fix-trait branch May 19, 2026 04:29
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.

A type implementing traits cannot retain its own methods in current trait convention

1 participant