Skip to content

x/tools/gopls: "file not found for pos = %d (%s)" crash in go/types  #69338

Open

Description

@adonovan
#!stacks
"runtime.gopanic" && "go/types.(*Checker).fileFor:+11"

This stack vD1W8g was reported by telemetry:

// fileFor returns the *ast.File which contains the position pos.
// If there are no files, the result is nil.
// The position must be valid.
func (check *Checker) fileFor(pos token.Pos) *ast.File {
	assert(pos.IsValid())
	// Eval and CheckExpr tests may not have any source files.
	if len(check.files) == 0 {
		return nil
	}
	for _, file := range check.files {
		if file.FileStart <= pos && pos < file.FileEnd {
			return file
		}
	}
	panic(check.sprintf("file not found for pos = %d (%s)", int(pos), check.fset.Position(pos))) // <--- here
}

The root cause is #69477 in go/types.

crash/crash
runtime.gopanic:+69
go/types.(*Checker).handleBailout:+7
go/types.(*Checker).Files.deferwrap1:+0
runtime.gopanic:+50
go/types.(*Checker).fileFor:+11
go/types.(*Checker).allowVersion:+3
go/types.(*Checker).genericExprList:+21
go/types.(*Checker).callExpr:+127
go/types.(*Checker).exprInternal:+357
go/types.(*Checker).rawExpr:+10
go/types.(*Checker).multiExpr:+2
go/types.(*Checker).assignVars:+31
go/types.(*Checker).stmt:+116
go/types.(*Checker).simpleStmt:=99
go/types.(*Checker).stmt:+210
go/types.(*Checker).stmtList:+9
go/types.(*Checker).funcBody:+23
golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (2)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Dups: vEHlHQ rRko4w ipCG3g X0G-gQ YALHSA NQ7Z2w kShApw Y2vk_g

Activity

  1. 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 Sep 7, 2024
  2. added this to the Unreleased milestone on Sep 7, 2024
  3. adonovan commented on Sep 7, 2024

    @adonovan
    MemberAuthor

    This stack vEHlHQ was reported by telemetry:

    crash/crash
    runtime.gopanic:+69
    go/types.(*Checker).handleBailout:+7
    go/types.(*Checker).Files.deferwrap1:+0
    runtime.gopanic:+50
    go/types.(*Checker).fileFor:+11
    go/types.(*Checker).allowVersion:+3
    go/types.(*Checker).genericExprList:+21
    go/types.(*Checker).callExpr:+127
    go/types.(*Checker).exprInternal:+357
    go/types.(*Checker).rawExpr:+10
    go/types.(*Checker).multiExpr:+2
    go/types.(*Checker).initVars:+51
    go/types.(*Checker).shortVarDecl:+61
    go/types.(*Checker).stmt:+113
    go/types.(*Checker).simpleStmt:=99
    go/types.(*Checker).stmt:+210
    go/types.(*Checker).stmtList:+9
    
    golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)
    

    Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

  4. adonovan commented on Sep 9, 2024

    @adonovan
    MemberAuthor

    This stack rRko4w was reported by telemetry:

    crash/crash
    runtime.gopanic:+69
    go/types.(*Checker).handleBailout:+7
    go/types.(*Checker).Files.deferwrap1:+0
    runtime.gopanic:+50
    go/types.(*Checker).fileFor:+11
    go/types.(*Checker).allowVersion:+3
    go/types.(*Checker).genericExprList:+21
    go/types.(*Checker).callExpr:+127
    go/types.(*Checker).exprInternal:+357
    go/types.(*Checker).rawExpr:+10
    go/types.(*Checker).suspendedCall:+4
    go/types.(*Checker).stmt:+142
    go/types.(*Checker).stmtList:+9
    go/types.(*Checker).funcBody:+23
    go/types.(*Checker).funcDecl.func1:+1
    go/types.(*Checker).processDelayed:+16
    
    golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)
    

    Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

  5. self-assigned this
    on Sep 16, 2024
  6. gopherbot commented on Sep 17, 2024

    @gopherbot
    Contributor

    Change https://go.dev/cl/613735 mentions this issue: go/types: compute effective Go version independent of token.Pos

  7. added a commit that references this issue on Sep 26, 2024
    9b1f8f3
  8. adonovan commented on Nov 25, 2024

    @adonovan
    MemberAuthor

    This stack X0G-gQ was reported by telemetry:

    golang.org/x/tools/gopls@v0.17.0-pre.2 go1.23.3 linux/amd64 vscode (4)
    

    This stack YALHSA was reported by telemetry:

    golang.org/x/tools/gopls@v0.17.0-pre.2 go1.23.3 linux/amd64 vscode (3)
    

    This stack NQ7Z2w was reported by telemetry:

    golang.org/x/tools/gopls@v0.17.0-pre.2 go1.23.3 linux/amd64 vscode (2)
    

    This stack kShApw was reported by telemetry:

    golang.org/x/tools/gopls@v0.17.0-pre.2 go1.23.3 linux/amd64 vscode (2)
    
  9. added a commit that references this issue on Mar 14, 2025
    5f9beff
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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions