Word30210/fix trait#10
Merged
Merged
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.
What
trait.inherent(class_table, methods): C & Mfor merging a class's own methods (kept in a separate table) into the class table; methods already present are not overwritten.Trait<D>,define,impl, andinherentinsrc/std/trait/init.luau.tests/std/trait/.check.luauto express the new convention — own methods live in a dedicated table and are merged viainherent— and demonstrate thatinherent'sC & Mreturn surfaces those methods at the type level..inherentcases totests/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,__indexhad to be widened with__index = Class :: {}. That cast erased the class table's type fromtypeof(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.inherentcarves own methods out into a separate, dedicated table whose type is captured byinherent'sC & Mreturn (and remains directly available astypeof(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 eachTrait.For<Self>— without forcing the duplicate-method intersection that motivated the:: {}workaround in the first place.defineandimplare unchanged; the addition is purely additive.Closes #8.
Checklist
Required
lute run ./scripts/checker.luau -- ./src ./tests ./scriptspasseslute run ./scripts/tester.luaupassesCloses #19)Functional Validation
.spec.luauand/or.check.luauadded or updated)Configuration & Docs
README.md/README.ko.md/CLAUDE.md)pesde.toml/mise.tomlIf Applicable