cloudwego / cloudwego/abcoder

Trait methods have the same name as regular methods

オープン
#44 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
390
フォーク
57
平均マージ
2日 21時間
マージ済み PR(30日)
1

説明

处理同名方法和 trait 方法

考虑 rust 的例子:
```rust
struct Foo;
impl Foo { fn say(&self) { println!("foo.say") } }
trait Bar { fn say(&self); }
impl Bar for Foo { fn say(&self) { println!("Bar.say") } }
fn g(x: &T) { x.say(); }
```

Foo 的 say 方法应该有哪个?
按理说应该是 Foo.say,不是 Bar.say。
但是当前实现里,后者名为 say 也归属于 Foo,所以导致了重名函数的问题。
并且因为 uniast.Type.Methods[name] 只有一个函数,所以会导致 parser 输出不稳定。

要解决这个问题,有两个方法1
1. 让 Bar.say 也归属于 Foo,把 uniast.Type.Methods 变成 name -> list[Identity]
2. 让它单独归属于一个 trait object(标准 Rust 方法),需要在 collect 阶段处理 symbol kind Object。

同样,考虑到 C++ 有 OOP,类似问题存在,比如 Child.foo 重载 Parent.foo。
但是解决很简单,用亲类和后代类来区分就好。
(当然,如果有 C++ concept 了的话,需要更好的设计,但先不考虑)

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start by tracing how parser output populates uniast.Type.Methods and how the collect stage handles symbol kind Object. Compare the Rust trait-method collision with the C++ parent/child method case described in the issue. Done means choosing and implementing a stable representation that distinguishes same-named methods without unstable parser output.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, go, rust
領域
compilers, devtools
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。