Skip to content

Commit bf1d23f

Browse files
authored
fix: miss dependencies on value expr (#126)
1 parent 3d0fab1 commit bf1d23f

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

lang/golang/parser/file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func (p *GoParser) parseVar(ctx *fileContext, vspec *ast.ValueSpec, isConst bool
151151
ti := ctx.GetTypeInfo(*val)
152152
v.Type = &ti.Id
153153
v.IsPointer = ti.IsPointer
154+
for _, dep := range ti.Deps {
155+
v.Dependencies = InsertDependency(v.Dependencies, NewDependency(dep, ctx.FileLine(vspec.Type)))
156+
}
154157
} else {
155158
v.Type = typ
156159
}
@@ -179,6 +182,7 @@ func (p *GoParser) parseVar(ctx *fileContext, vspec *ast.ValueSpec, isConst bool
179182
continue
180183
}
181184
id := NewIdentity(mod, path, sel.Sel.Name)
185+
v.Dependencies = InsertDependency(v.Dependencies, NewDependency(id, ctx.FileLine(*val)))
182186
// refer val's define
183187
if err := p.referCodes(ctx, &id, p.opts.ReferCodeDepth); err != nil {
184188
fmt.Fprintf(os.Stderr, "failed to get refer code for %s: %v\n", id.Name, err)

testdata/go/0_golang/pkg/refer.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
// Copyright 2025 CloudWeGo Authors
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// https://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
15-
// Copyright 2024 CloudWeGo Authors
162
//
173
// Licensed under the Apache License, Version 2.0 (the "License");
184
// you may not use this file except in compliance with the License.
@@ -29,6 +15,7 @@
2915
package pkg
3016

3117
import (
18+
"a.b/c/pkg/entity"
3219
"github.com/bytedance/sonic"
3320
)
3421

@@ -74,3 +61,5 @@ type Case_Annoy_Struct struct {
7461
}
7562
C int
7663
}
64+
65+
const Case_Ref_Const = entity.G1

0 commit comments

Comments
 (0)