golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.71k stars 17.5k forks source link

x/tools/go/analysis/internal/checker: support RunDespiteErrors #67790

Closed adonovan closed 2 months ago

adonovan commented 3 months ago

The Go analysis framework allows an Analyzer to indicate that it is safe to run even in the presence of syntax and type errors, by setting RunDespiteErrors. However, the internal/checker package (used by {single,multi}checker) doesn't support it, as can be verified by running this main program:

go/analysis/passes/copylock/main.go

// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build ignore

// The copylock command applies the golang.org/x/tools/go/analysis/passes/copylock
// analysis to the specified packages of Go source code.
package main

import (
    "golang.org/x/tools/go/analysis/passes/copylock"
    "golang.org/x/tools/go/analysis/singlechecker"
)

func main() { singlechecker.Main(copylock.Analyzer) }

on the test case in https://github.com/golang/go/issues/67787. The output is:

$ copylock -v ./...
-: # rsc.io/tmp/goplsbug
./x.go:8:31: T (type) is not an expression
./x.go:8:31: T (type) is not an expression
copylocks: 2 errors during loading

CL https://go.dev/cl/383974 purports to have added support for RunDespiteErrors, but the heuristic it uses to classify errors as typeParseError is evidently incorrect.

@zpavlinovic

gopherbot commented 3 months ago

Change https://go.dev/cl/591117 mentions this issue: internal/checker: run despite all errors