Repository navigation
Pass a call's receiver the way C, C++ and Rust can reach it [patch] - #328
Open
matt-edmondson wants to merge 2 commits into
Open
matt-edmondson wants to merge 2 commits into
matt-edmondson wants to merge 2 commits into
Conversation
C passed the address of a receiver that was already a pointer or reference, and took the address of a call's result, so no method chain compiled. C now passes a pointer as it is and puts a call's result in a one-element array compound literal. C++ reaches through a pointer with ->, and Rust dereferences a raw pointer inside unsafe. Rust now scopes the static types of a function's parameters and locals to know which. Fixes #170 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018tZnrna9oooMZHDaLyXumk
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018tZnrna9oooMZHDaLyXumk
|
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.



Requested by Matt · project thread
Before: a method call on a
const T&orconst T*parameter generatedVec_length(&other)in C, which passes a pointer to a pointer. A chain such asv.twice().length()generatedVec_length(&Vec_twice(&v)), and no C compiler accepts the address of a call's result. C++ wroteother.length()on a pointer, and Rust wroteother.length()on a*const Vec. None of those compile.After: C passes a pointer or reference receiver as it is (
Vec2_length(other)). It wraps a call's result in a one-element array compound literal,Vec2_length((Vec2[]){ Vec2_twice(&v) }), which is an lvalue and decays to the pointer the function takes. C++ writesother->length(), and Rust writesunsafe { (*other).length() }.How: the receiver's indirection comes from the static-type scope in
StandardLanguageGenerator. C and C++ already pushed that scope. Rust now pushes it for function bodies and registers its locals. C also looks up a call's return type by the mangled name it gives a member function (Vec2_twice), because the shared lookup only knows the declared name. The base generator gainsSpellMemberAccess, which C++ overrides to write->. A receiver whose type is unknown is written as before.The C, C++ and Rust compile tests each gain one case. It covers a call on a reference parameter, a call on a pointer parameter, and a chained call, all built from the shared
ReceiverExemplarfixture. Each case compiles the output with warnings as errors, runs the driver, and checks the exit code. All 3 fail without the fix. The full suite passes: 1386 tests, 0 failures.This doesn't cover a call on a type (static methods, #300) or on
self(#141).Fixes #170
Generated by Claude Code