Fix ApplyInterface interface source resolution#1443
Conversation
|
It also adds parser fixtures and a new test to validate that Affected Areas• This summary was automatically generated by @propel-code-bot |
| } | ||
| skip++ | ||
| } | ||
| cmd := exec.Command("go", "list", "-json", ".") |
There was a problem hiding this comment.
[Documentation] The PR intent/summary says GetInterfacePath now uses golang.org/x/tools/go/packages, but the implementation here shells out to go list. If the switch to go list is intentional, please update the PR description to avoid confusion; otherwise, consider using packages.Load (e.g., with packages.NeedFiles) to align with the stated goal.
Context for Agents
The PR intent/summary says `GetInterfacePath` now uses `golang.org/x/tools/go/packages`, but the implementation here shells out to `go list`. If the switch to `go list` is intentional, please update the PR description to avoid confusion; otherwise, consider using `packages.Load` (e.g., with `packages.NeedFiles`) to align with the stated goal.
File: internal/parser/export.go
Line: 59| } | ||
| skip++ | ||
| } | ||
| cmd := exec.Command("go", "list", "-json", ".") |
There was a problem hiding this comment.
[Logic] If the runtime.Caller scan never finds a non-gen file, file stays empty and filepath.Dir(file) becomes ".", so go list runs in the current working directory. That can resolve the wrong package and make interface discovery fail silently. Guard against file == "" before running go list to surface a clear error.
| cmd := exec.Command("go", "list", "-json", ".") | |
| if file == "" { | |
| return nil, fmt.Errorf("go list package %s fail: failed to locate caller file", arg.PkgPath()) | |
| } | |
| cmd := exec.Command("go", "list", "-json", ".") |
Context for Agents
If the `runtime.Caller` scan never finds a non-gen file, `file` stays empty and `filepath.Dir(file)` becomes ".", so `go list` runs in the current working directory. That can resolve the wrong package and make interface discovery fail silently. Guard against `file == ""` before running `go list` to surface a clear error.
```suggestion
if file == "" {
return nil, fmt.Errorf("go list package %s fail: failed to locate caller file", arg.PkgPath())
}
cmd := exec.Command("go", "list", "-json", ".")
```
File: internal/parser/export.go
Line: 59Dismissing previous approval: 1 new comment(s) require attention based on Default policy
Summary
ApplyInterfaceinterface source resolution more robust by usinggo list -jsonto locate the package directory and its GoFilesgo/build.Default.Import(can be sensitive to unusual GOROOT/toolchain setups)golang.org/x/tools/go/packagesto reduce toolchain-compat issues in some lintersTests