Repository navigation
§9.5: receiver fields in scope by bare name in their type's own module (#1930) - #2034
Merged
Merged
Conversation
ehartford
force-pushed
the
impl-1930
branch
5 times, most recently
from
October 4, 2026 00:51
b54287b to
ef6e5d4
Compare
added 15 commits
October 4, 2026 07:18
…binding is the one diagnostic (#1930)
…module's methods (§9.5, #1930): src, lib/std, build
…keep their C parameter names (#1930)
…llee, shorthand, generic owner; ext-module refusal; each shadowing error (#1930)
…mples/service (§9.5, #1930) Spec change: per the 2026-09-22 ruling an example the new rule breaks is updated in the same change. examples/service/src/cache/redis.w: RedisCache.new's parameter `prefix` shadowed the field; it is now `key_prefix`. The compile_errors fixtures keep testing their own error under a renamed binding.
… outside §9.5's bare field names; fixture for self.field beside a clashing prelude fn (#1930)
…ched by the #1930 rename)
…edundant -> Unit on signatures the rename touched (#1930)
… rename touched (#1930)
…owing error, as for a prelude function (#1930)
…eclarations; §18.2 builtins.name reaches every prelude fn and intrinsic (#1930)
…ures for qualified forms, self-names, builtins (#1930)
added 2 commits
October 4, 2026 07:18
…very other emitted function does The wrapper is a method of the struct in the struct's own module, where a field is in scope by its bare name (§9.5). It was the one emitted function that kept the bare C parameter names, so `holder_init(h, cmp)` over a `holder.cmp` field migrated to a method whose parameter shadows the field (behav_migrate_fn_typedef_pointer, red in the battery). It now takes ci_param_signature_name (`__param_cmp`), which no C field has.
…param_count` The assertion checks that the wrapper calls the aliased C symbol; the parameter spelling follows ci_param_signature_name, as the extern declaration's `__param_text` above it already does.
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.
Implements Eric's 2026-10-03 §9.5 ruling (#1930; the words landed in spec v7.17, #2021):
What "the type's own module" is
§18.1: "One file is one module." I checked it by compiling:
impl T:in another file is allowed, and a private fn of T's file is refused there ("symbol is private to module 'counter.w'"). So a method is in its type's own module when the file that declares the method also declares the struct or union. Generated text does not count as a module someone wrote: a c_import's translation and a renderedc facade(<c_import …>,<facade …>,<toolchain facade …>files) are excluded, and so are compiler derives, which carry their type's span. Their C parameter names stay as they are.Mechanism
AstPool.resolve_receiver_field_namesruns in the frontend after imports and the comptime transform, before freeze. It is file-local and purely syntactic, and it does not decide what a name means. In each own-module instance method body, every bare identifier that names a receiver field becomesself.<field>in place, so MIR, codegen, ownership and capture all see an ordinary field place. A callee becomes(self.<field>)(..): it calls the field's value and never finds a method. Parameters of a field's name are not rewritten. Names a body binds are not rewritten either, so the refused binding is the only diagnostic, not the start of a cascade.refuse_receiver_field_shadow(inscope_put_at/ consuming rebind) rejects any parameter or local binding with a field's name: params,let, patterns,for, closure params and destructures.check_receiver_field_namerejects a rewritten bare name that also resolves, from the current module, to a global, a module-level function, a type, a variant or an import namespace.self.<field>.self.fix.Calls I made (Eric may want to confirm)
panic,printordropmakes the bare name an error.builtins.panic(afteruse std.builtins) orself.panicworks, and is pinned inbehav_receiver_field_clash_spelled.w.math.PIturning intoself.math.PI).src,channel) are not module-level functions, so a field wins there.gauge.limit()from within gauge.w is "undefined variable"). A field that clashes with a same-module function therefore leaves that function unreachable from the type's methods, and "the qualified name remains valid" has nothing to point at. The census found no such site in the tree.let { repr, other: _ } = selfinside a type's ownmove fnnow has to be spelledlet { repr: r, other: _ } = self. Two fixtures were updated.Migration (renamed bindings, one per binding name per method)
zcu×19, Resolvepool×10, Sema 12, Codegen 6, ComptimeEval 6, Zcu 6, Parser 6, Xz 7, Diagnostic 6 + foundation/Diagnostic 4, CCodegen 5, MirLower 3, CImport 2, Bzip2 1, CodegenUnits 1)examples/service/src/cache/redis.wRedisCache.new(prefix)→key_prefix(spec change, 2026-09-22 ruling: example updated in the same change)let dt = self.dtis an ext-module method and is unaffected. The UAT fixtures have no methods.No bare use of a field that clashes with a function or global existed anywhere, so the 16 census clashes needed no edits. Three signatures that the renames touched lost a redundant
-> Unit(unit-return-review).self.was not stripped anywhere. That is optional style and not part of this change.Tests
New fixtures:
behav_receiver_field_bare_name.w: read,mut fnwrite and compound write, aforover a field, a closure inmut fn/move fn, a callee field, struct-literal shorthand, a generic owner, andself.fieldbeside the bare field.behav_receiver_field_ext_module.wandbehav_receiver_field_clash_spelled.w.err_1930_*×8: ext-module bare field, param, local, closure param, pattern binding, field vs fn, field vs global, field vs prelude fn.Failing-first: the seed refuses the bare-name fixture ("undefined variable") and accepts every
err_1930program.Results on stage1:
audit:all647853 facts, 0 violations;--validate-allok;--debug-allocleak 0; 120 targeted behavior tests green;:gategreen;:drop-audit254 cells, 0 regressions. Thefn-receiver closure crash found while writing these fixtures is #2025, fixed in the stacked #2040.