Skip to content

SA4023: staticcheck panics "unhandled type *ir.ArrayConst" #1397

Closed

Description

@llkitaev

staticcheck -version
staticcheck 2023.1.3 (v0.4.3)

staticcheck -debug.version

Compiled with Go version: go1.20.2
Main module:
        honnef.co/go/tools@v0.4.3 (sum: h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw=)
Dependencies:
        github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
        golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
        golang.org/x/mod@v0.7.0 (sum: h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=)
        golang.org/x/sys@v0.3.0 (sum: h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=)
        golang.org/x/tools@v0.4.1-0.20221208213631-3f74d914ae6d (sum: h1:9ZNWAi4CYhNv60mXGgAncgq7SGc5qa7C8VZV8Tg7Ggs=)

go version
go version go1.20.2 darwin/amd64

Example:

package main

import "github.com/google/uuid"

type ChatID uuid.UUID
type UserID uuid.UUID

type Types interface {
 ChatID | UserID
}

func Parse[T Types](val string) (T, error) {
 parsed, err := uuid.Parse(val)
 if err != nil {
  return T{}, err  // problem line
 }
 return T(parsed), nil
}
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
panic: internal error: unhandled type *ir.ArrayConst

goroutine 319 [running]:
honnef.co/go/tools/analysis/facts/nilness.impl.func1({0x1e90840, 0xc000223c80})
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/analysis/facts/nilness/nilness.go:239 +0x854
honnef.co/go/tools/analysis/facts/nilness.impl.func1({0x16115c8, 0xc000133c80})
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/analysis/facts/nilness/nilness.go:147 +0x9b8
honnef.co/go/tools/analysis/facts/nilness.impl(0xc00067ef00, 0xc000563040, 0xc000018db0)
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/analysis/facts/nilness/nilness.go:246 +0x372
honnef.co/go/tools/analysis/facts/nilness.run(0xc00067ef00)
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/analysis/facts/nilness/nilness.go:66 +0x11a
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc00010f4a0, {0x160ee18?, 0xc0002b72c0})
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/lintcmd/runner/runner.go:992 +0x76a
honnef.co/go/tools/lintcmd/runner.genericHandle({0x160ee18?, 0xc0002b72c0}, {0x160ee18?, 0xc00014c1e0?}, 0x0?, 0xc00036b030, 0xc0002811a0)
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/lintcmd/runner/runner.go:817 +0x130
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
        /Users/llkitaev/go/pkg/mod/honnef.co/go/tools@v0.4.3/lintcmd/runner/runner.go:1061 +0x70a

Activity

  1. added
    needs-triage
    on Apr 23, 2023
  2. changed the title [-]SA4023: staticchecks panics "unhandled type *ir.ArrayConst"[/-] [+]SA4023: staticcheck panics "unhandled type *ir.ArrayConst"[/+] on Apr 23, 2023
  3. removed
    needs-triage
    on Apr 23, 2023
  4. Antonboom commented on Oct 29, 2023

    @Antonboom

    +1 with better stack trace

    $ golangci-lint version           
    golangci-lint has version 1.54.0 built with go1.21.0 from c1d8c565 on 2023-08-09T11:50:00Z
    
    ERRO [runner] Panic: SA4023: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *nilness.Result: goroutine 1066 [running]:
    runtime/debug.Stack()
            runtime/debug/stack.go:24 +0x64
    github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
            github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:109 +0x224
    panic({0x1015c3300?, 0x14005591500?})
            runtime/panic.go:914 +0x218
    honnef.co/go/tools/staticcheck.CheckTypedNilInterface(0x14006713380)
            honnef.co/go/tools@v0.4.3/staticcheck/lint.go:4527 +0xa3c
    github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x14001615a80)
            github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:195 +0x900
    github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
            github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:113 +0x20
    github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x140015d94a0, {0x101262c6e, 0x6}, 0x14002415f30)
            github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
    github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x140030d2b00?)
            github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:112 +0x78
    github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x14001615a80)
            github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0
    created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 155
            github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x184 
    WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: SA4023: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *nilness.Result 
    

    Looks like we need safe type assertions here.

  5. added a commit that references this issue on Feb 27, 2024
    b3ee554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions