Skip to content

Commit b6480ac

Browse files
authored
(fix) output instability (#55)
* fix: defer assignment visited to avoid unstable outcome * fix(tests): do not test functions with identical names They lead to output instabilities. We *should* fix the instabilities instead, but for now let's ignore the case.
1 parent 227e748 commit b6480ac

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

lang/collect/export.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,37 +161,40 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
161161
return id, nil
162162
}
163163

164-
name := symbol.Name
165-
if name == "" {
166-
if refName == "" {
167-
e = fmt.Errorf("both symbol %v name and refname is empty", symbol)
168-
return
169-
}
170-
// NOTICE: use refName as id when symbol name is missing
171-
name = refName
172-
}
164+
// Check NeedStdSymbol
173165
file := symbol.Location.URI.File()
174166
mod, path, err := c.spec.NameSpace(file)
175167
if err != nil {
176168
e = err
177169
return
178170
}
179-
180171
if !c.NeedStdSymbol && mod == "" {
181172
e = ErrStdSymbol
182173
return
183174
}
184175

185-
tmp := uniast.NewIdentity(mod, path, name)
186-
id = &tmp
187-
visited[symbol] = id
188-
189-
// Load eternal symbol on demands
176+
// Load external symbol on demands
190177
if !c.LoadExternalSymbol && (!c.internal(symbol.Location) || symbol.Kind == SKUnknown) {
191178
e = ErrExternalSymbol
192179
return
193180
}
194181

182+
// Construct Identity and save to visited
183+
name := symbol.Name
184+
if name == "" {
185+
if refName == "" {
186+
e = fmt.Errorf("both symbol %v name and refname is empty", symbol)
187+
return
188+
}
189+
// NOTICE: use refName as id when symbol name is missing
190+
name = refName
191+
}
192+
tmp := uniast.NewIdentity(mod, path, name)
193+
id = &tmp
194+
// Save to visited ONLY WHEN no errors occur
195+
visited[symbol] = id
196+
197+
// Walk down from repo struct
195198
if repo.Modules[mod] == nil {
196199
repo.Modules[mod] = newModule(mod, "", c.Language)
197200
}

testdata/rust2/src/entity/inter.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ pub trait Addable {
3535

3636
pub struct AnyInt(i64);
3737

38-
impl AnyInt {
39-
pub fn id() -> i64 {
40-
0
41-
}
42-
pub fn add(&self, b: i64) -> i64 {
43-
self.0 + b
44-
}
45-
}
38+
//impl AnyInt {
39+
// pub fn id() -> i64 {
40+
// 0
41+
// }
42+
// pub fn add(&self, b: i64) -> i64 {
43+
// self.0 + b
44+
// }
45+
//}
4646

4747
impl Addable for AnyInt {
4848
fn add(&self, b: i64) -> i64 {

0 commit comments

Comments
 (0)