Skip to content

fix(types): order a method call only before fns of the receiver type's module - #480

Merged
Allianaab2m merged 1 commit into
mainfrom
fix/method-call-generalization
Oct 30, 2026
Merged

Allianaab2m merged 1 commit into
mainfrom
fix/method-call-generalization

Conversation

@Allianaab2m

Copy link
Copy Markdown
Member

概要

メソッド呼び出し x.f(...) の推論順の辺(#467)を,仕様どおり「第 1 引数の型を定義するモジュールの fn」だけに張るようにします.これまではモジュールを見ずに,名前が f で第 1 引数が名前付きの型の fn すべてに辺を張っていました.

quince で依存を x/dynamic v0.5.0,x/json v0.3.0,x/shape v0.3.1 に上げると,test の fn get(url: String) -> Response が json の .chars().get(d) や Lib 内の .get( と同じグループに入り(4 モジュール,23 個の fn),get の R に別の fn の集合型引数が漏れて E0402(test 13 本)と E0403 が出ていました.String を定義するのは core の String モジュールなので,この get はメソッドとして呼ばれることがありません.

仕様

  • [type.rules](メソッドの候補は x の型を定義するモジュールの fn)
  • proposals/method-call.md

変更点

  • check::may_be_method で,第 1 引数に書かれた型の定義モジュール(methods::defining_module)が fn 自身のモジュールと一致するときだけ候補にする

最小再現

fn run(f: fn() -> Int) -> Int {
  [f()].get(0).or(0)
}

fn get(url: String) -> Int {
  run(fn() { url.length() })
}

fn main() -> Int {
  get("x")
}

修正前は get: fn(String) -> Int use '1 になり,main で E0402.修正後は get: fn(String) -> Int.

テスト

  • crates/emela-types/tests/methods.rs に a_method_call_does_not_order_before_fns_of_other_modules を追加(修正前に失敗することを確認)
  • cargo test --workspace,cargo clippy -p emela-types --all-targets,cargo fmt --check,scripts/spec.py check
  • quince の改名前の test(fn get)で emela check が通り,emela test が 15 passed

既知の制約 / follow-up

…s module

A method call x.f(...) got an edge to every fn named f whose first
parameter was written as a named type, in any module. A fn such as
`fn get(url: String)` in a test module could then share a group with
unrelated fns that call `.get(`, and its R leaked a set type parameter
of another fn in the group (E0402, E0403).

Only fns whose first parameter has a type defined by their own module
can be found by a method call ([type.rules]), so only those get edges.
@Allianaab2m Allianaab2m added area: compiler Compiler frontend, type checker, lowering, or diagnostics kind: compiler-bug Incorrect compiler behavior rather than user code or documentation labels Oct 30, 2026
@Allianaab2m
Allianaab2m added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 15c55f5 Oct 30, 2026
11 checks passed
@Allianaab2m
Allianaab2m deleted the fix/method-call-generalization branch October 30, 2026 07:00
@emela-bot emela-bot Bot mentioned this pull request Oct 30, 2026
Allianaab2m added a commit to emela-lang/quince that referenced this pull request Oct 30, 2026
0.26.1 でメソッド呼び出しの推論の問題(emela-lang/emela#480)が直り,test の helper を get のまま書いても E0403 にならなくなった.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Compiler frontend, type checker, lowering, or diagnostics kind: compiler-bug Incorrect compiler behavior rather than user code or documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant