Skip to content

Commit 0b8a917

Browse files
committed
Go: Fix crash if WorkspaceFile.Go is nil
1 parent 46c553e commit 0b8a917

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

go/extractor/project/project.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ type GoVersionInfo struct {
5858
// 1. The Go version specified in the `go.work` file, if any.
5959
// 2. The greatest Go version specified in any `go.mod` file, if any.
6060
func (workspace *GoWorkspace) RequiredGoVersion() GoVersionInfo {
61-
if workspace.WorkspaceFile != nil {
61+
if workspace.WorkspaceFile != nil && workspace.WorkspaceFile.Go != nil {
6262
// If we have parsed a `go.work` file, return the version number from it.
6363
return GoVersionInfo{Version: workspace.WorkspaceFile.Go.Version, Found: true}
6464
} else if workspace.Modules != nil && len(workspace.Modules) > 0 {
6565
// Otherwise, if we have `go.work` files, find the greatest Go version in those.
6666
var greatestVersion string = ""
6767
for _, module := range workspace.Modules {
68-
if module.Module != nil {
68+
if module.Module != nil && module.Module.Go != nil {
6969
// If we have parsed the file, retrieve the version number we have already obtained.
7070
if greatestVersion == "" || semver.Compare("v"+module.Module.Go.Version, "v"+greatestVersion) > 0 {
7171
greatestVersion = module.Module.Go.Version

0 commit comments

Comments
 (0)