Repository navigation
feat: x.f(a) でメソッド呼び出しを書ける - #467
Merged
Merged
Conversation
[api.std.http.response] で headers から header_values に改名した関数が, [lib] のコード例では古い名前のままだった.
x.f(a) を M.f(x, a) として呼ぶ.M は x の型を定義するモジュールで, f は第1引数の型の head がその型である fn.型が実装する trait のうち, 呼び出し側で名前で見える trait の self を取る関数も同じ形で呼べる ([type.rules]). - resolve: E0334(型の field と同じ名前の fn)と,モジュールごとに 名前で見える trait の一覧 - types: method lookup,E0312/E0313/E0314 の拡張,E0335(候補が複数). 型宣言のない関数を method として呼べるよう,推論の順序に同じ名前の 候補への辺を足す - core: method call を M.f(x, a) と同じ形に lowering する - LSP: `.` の後の補完に method を出し,定義ジャンプ・参照・rename で method call を関数の参照として扱う - std: List.join を足して String.join を deprecated にする. Request.headers と Response.headers を header_values に改名し, Cause の private field を failure に改名する Implements proposals/method-call.md.
Allianaab2m
marked this pull request as ready for review
October 28, 2026 00:58
Int.compare, Int64.compare, Duration.compare, Instant.compare を消す. これらの型は Ord を満たすので,メソッド呼び出し n.compare(m) が常に E0335 になっていた(proposals/remove-compare.md, #468).min, max と TestClock は Ord.compare を呼ぶ. methods__method_call_errors のスナップショットも撮り直す(CI の失敗).
[api.int], [api.int64], [api.std.duration], [api.std.instant] から compare の行を消し,[target.number] と [open.list] の 44 を直す. proposals/remove-compare.md を implemented にする.
# Conflicts: # crates/emela-driver/tests/diagnostics.rs # crates/emela-types/tests/spec_examples.rs
Merged
This was referenced Oct 29, 2026
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: proposals/method-call.md, proposals/remove-compare.md
Closes #463
Closes #469
規則とテスト
[type.rules]x.f(a)は field → x の型を定義するモジュールの fn(第1引数の head が T)→ 名前で見える trait のselfを取る関数,の順に探すemela-types/tests/methods.rs(method_calls_have_the_type_of_the_call,core_functions_are_methods,fields_and_trait_functions)M.f(x, a)の呼び出しと同じ.名前付き引数も同じmethods.rs::method_calls_have_the_type_of_the_callprograms/method_calls.emel(JS・C・WASM)diagnostics.rs::method_call_diagnostics(s.secret()),method_calls_without_imports_check_cleanlyimport L.{T},自モジュールのものだけ.L.Tでしか書けない trait は探さないmethod_call_diagnostics(s.label()),fields_and_trait_functionsfields_and_trait_functions(total,through_super,unbounded)core_functions_are_methods(not_strings)log.infoは operation のままcall it as ...)method_call_diagnostics,methods.rs::method_call_errorsto call f)resolve.rs::fn_named_like_a_field,method_call_diagnosticsmethod_call_diagnosticsM.f(x, a)と同じ形emela-core/tests/lower.rs::method_calls_lower_as_calls[api.list]List.join,[api.string]String.joinは deprecatedprograms/method_calls.emel,wasm_parity のstrings_extended(String.join)[api.std.http.*]header_valuesへの改名programs/http_values.emel,run.rs[lsp.completion]field の後に method(第1引数を除いた型)server.rs::method_calls_in_navigation_and_completion,completion_after_dot[lsp.navigation]method call を関数の参照として扱うmethod_calls_in_navigation_and_completionspec_examples.rs::spec_method_calls診断コード
E0334・E0335 は spec で番号が決まっていたので,その番号で実装した(
code.rsに追加).実装の判断
check::groupsのコメント)x.f(呼び出しなし)では辺を足さないので,未推論の候補は書かれた第1引数の型で判定するM.f(...)で名前付き引数つきで呼ぶと今もエラーになる(既存の制限).method call ではパラメータ名からラベルを補うCauseの private field はfailureに改名した(dbgの表示がCause(failure: <fn>)に変わる)String.joinはList.joinに置き換えた[lib]のコード例に古いheadersが残っていたので,別コミットで直した報告
n.compare(m)が E0335 になる問題は,proposals/remove-compare.md(proposal: Remove the compare functions that Ord already gives #468)でInt.compare,Int64.compare,Duration.compare,Instant.compareを消して解決した.この PR で実装し,run.rsでbig.compare(one)などのメソッド呼び出しを確かめているn = 42)にn.to_string()と書くと仕様どおり E0314 になるString.lengthをまだ扱えない(既存)ので,runtime の program ではbyte_sizeを使った手元での確認
String.join置き換え後の全体実行,example,tests/lawsは手元で回していない.CI で確認する