fix: rewrite self/static/parent in variadic parameter types#427
Merged
nahime0 merged 4 commits intoJul 8, 2026
Conversation
A `self`-typed variadic parameter (`concat(self ...$items)`) failed with "Cannot use 'self' as a type outside of a class". The pass that rewrites the relative class types `self`/`static`/`parent` to the enclosing class visited each method's regular parameters and its return type, but not the variadic parameter's type, so `self` survived to type resolution and was rejected. Rewrite the variadic parameter's type annotation alongside the regular parameters and the return type. Adds a codegen regression test for a `self ...$items` variadic parameter.
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
A
self-typed variadic parameter fails to compile:→
Cannot use 'self' as a type outside of a classself/static/parentalready work everywhere else — regular parameter types, return types, property types.Why
substitute_relative_class_types_in_methodsrewrites the relative class typesself/static/parentto the concrete enclosing class before type resolution. It walks each method's regular parameters (method.params) and its return type (method.return_type) — but not the variadic parameter's type (method.variadic_type), which is a separate field. Soselfon a variadic param survives toresolve_type_expr, which rejects a bareselfas "outside of a class" (relative types are expected to have been rewritten already).How
Rewrite
method.variadic_typealongside the regular params and the return type. Three lines.Tests
tests/codegen/oop/relative_types.rs— new regression testtest_self_typed_variadic_param: astatic concat(self ...$items): selfcompiles and runs (Bag::concat(...)→abc). Existing relative-types and variadic codegen tests still pass.🤖 Generated with Claude Code