Skip to content

x/tools/gopls: OOB index crash in completion.expectedReturnStmtType #70636

Closed
@adonovan

Description

@adonovan
#!stacks
"runtime.goPanicIndex" && "go/types.(*Tuple).At" && "completion.expectedReturnStmtType"

Issue created by stacks.

// expectedReturnStmtType returns the expected type of a return statement.
// Returns nil if enclosingSig is nil.
func expectedReturnStmtType(enclosingSig *types.Signature, node *ast.ReturnStmt, pos token.Pos) types.Type {
	if enclosingSig != nil {
		if resultIdx := exprAtPos(pos, node.Results); resultIdx < len(node.Results) {
			return enclosingSig.Results().At(resultIdx).Type() // <--- At panics
		}
	}
	return nil
}

This stack 69yMYw was reported by telemetry:

golang.org/x/tools/gopls@v0.17.0-pre.3 go1.23.2 linux/amd64 other,vscode (5)

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
goplsIssues related to the Go language server, gopls.
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Dec 2, 2024
adonovan

adonovan commented on Dec 2, 2024

@adonovan
MemberAuthor

Closely related to #70634.

added this to the Unreleased milestone on Dec 2, 2024
findleyr

findleyr commented on Dec 2, 2024

@findleyr
Member

This is indeed a logic bug, as described in #70634 (comment).

self-assigned this
on Dec 2, 2024
gopherbot

gopherbot commented on Dec 2, 2024

@gopherbot
Contributor

Change https://go.dev/cl/632936 mentions this issue: gopls/internal/golang/completion: fix crash with extra results

1 remaining item

gopherbot

gopherbot commented on Dec 4, 2024

@gopherbot
Contributor

Change https://go.dev/cl/633706 mentions this issue: gopls/internal/golang/completion: fix crash with extra results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/telemetry-wins

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @adonovan@gopherbot@findleyr@gabyhelp

      Issue actions

        x/tools/gopls: OOB index crash in completion.expectedReturnStmtType · Issue #70636 · golang/go