Skip to content

Commit 79484dc

Browse files
authored
fix(go): incorrect id for dot-imported symbols (#122)
1 parent e8eef7f commit 79484dc

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lang/golang/parser/file.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,15 @@ func (p *GoParser) parseASTNode(ctx *fileContext, node ast.Node, collect *collec
394394
// return false
395395
// }
396396
if use, ok := ctx.pkgTypeInfo.Uses[expr]; ok {
397-
id := NewIdentity(ctx.module.Name, ctx.pkgPath, callName)
397+
pkg := use.Pkg()
398+
if pkg == nil {
399+
return true
400+
}
401+
mod, err := ctx.GetMod(pkg.Path())
402+
if err != nil {
403+
return true
404+
}
405+
id := NewIdentity(mod, pkg.Path(), use.Name())
398406
dep := NewDependency(id, ctx.FileLine(expr))
399407
// type name
400408
if _, isNamed := use.(*types.TypeName); isNamed {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// 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+
package pkg
16+
17+
import . "a.b/c/pkg/entity"
18+
19+
var G2 = G1
20+
21+
var I1 Integer
22+
23+
type S MyStructD
24+
25+
func CaseMergeRef() MyStruct {
26+
_ = G1 + G2
27+
return MyStruct{
28+
MyStructD: MyStructD{},
29+
}
30+
}

0 commit comments

Comments
 (0)